#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector a(n, vector<int>(k));
for (auto& v : a)
for (int& x : v)
cin >> x;
reverse(a.begin(), a.end());
const int mod = 1e9 + 7;
vector<int> dp(k, 1);
vector<int> last(k, 1e9 + 1);
for (int i = 0; i < n; i++) {
vector<int> new_dp(k);
for (int j = 0; j < k; j++) {
int z = lower_bound(last.begin(), last.end(), a[i][j]) - last.begin();
// cerr << i << ',' << j << ' ' << a[i][j] << ' ' << z << '\n';
if (z >= k)
new_dp[j] = 0;
else
new_dp[j] = dp[z];
}
last = a[i];
for (int j = k - 2; j >= 0; j--)
(new_dp[j] += new_dp[j + 1]) %= mod;
dp.swap(new_dp);
}
cout << dp[0] << '\n';
return 0;
}