#include using namespace std; signed main() { ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector> R(N, vector(M)); for (int i = 0; i < N; ++i) for (int j = 0; j < M; ++j) cin >> R[i][j]; vector, int>> dp(1 << M); for (int s = 1; s < 1 << M; ++s) dp[s] = make_tuple(vector(M), 0); for (int i = 0; i < N; ++i) { int ans = 0; for (int s = 1; s < 1 << M; ++s) { bool ng = false; bool better = false; vector cur(M); vector xxx(M); for (int j = 0; j < M; ++j) { if (s >> j & 1) { cur[j] = R[i][j]; xxx[j] = max(R[i][j], get<0>(dp[s])[j]); ng |= R[i][j] < get<0>(dp[s])[j]; better |= R[i][j] > get<0>(dp[s])[j]; } } if (!ng && better) dp[s] = make_tuple(cur, 1); else if (!ng && !better) ++get<1>(dp[s]); else if (ng && better) dp[s] = make_tuple(xxx, 0); ans += (__builtin_popcount(s) & 1 ? 1 : -1) * get<1>(dp[s]); // cout << "dp[" << i << "][" << s << "] = " << get<0>(dp[s])[0] << " " << get<0>(dp[s])[1] << " " << get<0>(dp[s])[2] << " " << get<1>(dp[s]) << endl; } cout << ans << endl; } return 0; }