#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#define fs first
#define se second

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
typedef pair<ld, ld> pdd;

int h, w;
char S[2001][2002];
int dp1[2001][2001];
int dp2[2001][2001];
int cut[2001];

int solve(int hs, int he, int ws, int we) {
    int h = he - hs + 1;
    int w = we - ws + 1;
    if (h == 1 || w == 1) return max(h, w);
    int ret = 0;
    if (h < w) {
        for (int i = hs; i <= he; ++i) {
            for (int j = i; j <= he; ++j) {
                dp1[i][j] = dp2[i][j] = 0;
            }
        }
        int m = (ws + we) / 2;
        {
            for (int i = hs; i < he; ++i) cut[i] = 0;
            for (int i = m; ws <= i; --i) {
                int mode = -1;
                for (int j = hs; j <= he; ++j) {
                    int nmode = (S[j][i] != S[j][i + 1]);
                    if (mode != nmode) cut[j - 1] = 1;
                    mode = nmode;
                }
                int pr = hs - 1;
                for (int j = hs; j < he; ++j) {
                    if (cut[j]) dp1[pr + 1][j] = m - i + 1, pr = j;
                }
                dp1[pr + 1][he] = m - i + 1;
            }
        }
        {
            for (int i = hs; i < he; ++i) cut[i] = 0;
            for (int i = m + 1; i <= we; ++i) {
                int mode = -1;
                for (int j = hs; j <= he; ++j) {
                    int nmode = (S[j][i] != S[j][i - 1]);
                    if (mode != nmode) cut[j - 1] = 1;
                    mode = nmode;
                }
                int pr = hs - 1;
                for (int j = hs; j < he; ++j) {
                    if (cut[j]) dp2[pr + 1][j] = i - m, pr = j;
                }
                dp2[pr + 1][he] = i - m;
            }
        }
        for (int i = hs; i <= he; ++i) {
            for (int j = he; i <= j; --j) {
                if (i > hs) dp1[i][j] = max(dp1[i][j], dp1[i - 1][j]), dp2[i][j] = max(dp2[i][j], dp2[i - 1][j]);
                if (j < he) dp1[i][j] = max(dp1[i][j], dp1[i][j + 1]), dp2[i][j] = max(dp2[i][j], dp2[i][j + 1]);
                ret = max(ret, (j - i + 1) * (dp1[i][j] + dp2[i][j]));
            }
        }
        ret = max({ ret, solve(hs, he, ws, m), solve(hs, he, m + 1, we) });
    }
    else {
        for (int i = ws; i <= we; ++i) {
            for (int j = i; j <= we; ++j) {
                dp1[i][j] = dp2[i][j] = 0;
            }
        }
        int m = (hs + he) / 2;
        {
            for (int i = ws; i < we; ++i) cut[i] = 0;
            for (int i = m; hs <= i; --i) {
                int mode = -1;
                for (int j = ws; j <= we; ++j) {
                    int nmode = (S[i][j] != S[i + 1][j]);
                    if (mode != nmode) cut[j - 1] = 1;
                    mode = nmode;
                }
                int pr = ws - 1;
                for (int j = ws; j < we; ++j) {
                    if (cut[j]) dp1[pr + 1][j] = m - i + 1, pr = j;
                }
                dp1[pr + 1][we] = m - i + 1;
            }
        }
        {
            for (int i = ws; i < we; ++i) cut[i] = 0;
            for (int i = m + 1; i <= he; ++i) {
                int mode = -1;
                for (int j = ws; j <= we; ++j) {
                    int nmode = (S[i][j] != S[i - 1][j]);
                    if (mode != nmode) cut[j - 1] = 1;
                    mode = nmode;
                }
                int pr = ws - 1;
                for (int j = ws; j < we; ++j) {
                    if (cut[j]) dp2[pr + 1][j] = i - m, pr = j;
                }
                dp2[pr + 1][we] = i - m;
            }
        }
        for (int i = ws; i <= we; ++i) {
            for (int j = we; i <= j; --j) {
                if (i > ws) dp1[i][j] = max(dp1[i][j], dp1[i - 1][j]), dp2[i][j] = max(dp2[i][j], dp2[i - 1][j]);
                if (j < we) dp1[i][j] = max(dp1[i][j], dp1[i][j + 1]), dp2[i][j] = max(dp2[i][j], dp2[i][j + 1]);
                ret = max(ret, (j - i + 1) * (dp1[i][j] + dp2[i][j]));
            }
        }
        ret = max({ ret, solve(hs, m, ws, we), solve(m + 1, he, ws, we) });
    }
    return ret;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> h >> w;
    for (int i = 1; i <= h; ++i) {
        cin >> S[i] + 1;
    }
    printf("%d\n", solve(1, h, 1, w));
    return 0;
}


Measured memory_bytes: 35456