```
class Solution {
public:
int uniquePaths(int m, int n) {
m--;
n--;
int res = 1;
for (int i = 1; i <= min(m, n); i++) {
res = static_cast<long long>(res) * (n + m - i + 1) / i;
}
return res;
}
};
```