#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400 + 10;
int dp[MAXN][MAXN], a[MAXN][MAXN];
short last[MAXN][MAXN * MAXN];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  memset(last, -1, sizeof last);
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int l = m - 1; l >= 0; l--)
      for (int r = l; r < m; r++) {
        if (r == l) {
          dp[l][r] = min(dp[l][r] + 1, i - last[l][a[i][l]]);
          continue;
        }
        if (a[i][r] == a[i][l]) {
          dp[l][r] = 0;
          continue;
        }
        dp[l][r] =
            min(dp[l][r] + 1, min(min(dp[l + 1][r], dp[l][r - 1]),
                                  i - max(last[r][a[i][l]], last[l][a[i][r]])));
      }
    for (int l = m - 1; l >= 0; l--)
      for (int r = l; r < m; r++) res = max(res, (r - l + 1) * dp[l][r]);
    for (int j = 0; j < m; j++) last[j][a[i][j]] = i;
  }
  cout << res;
}
