#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

vector<ii> ranges(int W, vi& d) {
    vector<ii> r;
    int curr_from = -1;
    rep(i, W) {
        if (curr_from == -1) {
            if (d[i] == 0) {
                ;
            } else {
                curr_from = i;
            }
        } else {
            if (d[i] == 0) {
                r.pb(ii(curr_from, i));
                curr_from = -1;
            } else {
                ;
            }
        }
    }
    if (curr_from != -1) {
        r.pb(ii(curr_from, W));
    }
    return r;
}

void append_range(map<ii,int>& r_next, map<ii,int>& r_prev, vector<ii>& r){
    int L = r.size();
    rep(i, L) {
        ii k = r[i];
        r_next[k] = max(r_next[k], 1);
    }

    for (auto p : r_prev) {
        ii x = p.first;
        int ph = p.second;

        for (int i=0; i<r.size(); ++i) {
            ii y = r[i];

            if (x.second <= y.first) {
                ;
            } else if (y.second <= x.first) {
                ;
            } else {
                if (x.first <= y.first && y.second <= x.second) {
                    // y部分だけ
                    r_next[y] = max(r_next[y], ph+1);
                } else if (y.first <= x.first && y.second <= x.second) {
                    ii k(x.first, y.second);
                    r_next[k] = max(r_next[k], ph+1);
                } else if (x.first <= y.first && x.second <= y.second) {
                    ii k(y.first, x.second);
                    r_next[k] = max(r_next[k], ph+1);
                } else if (y.first <= x.first && x.second <= y.second) {
                    r_next[x] = max(r_next[x], ph+1);
                }
            }
        }
    }
}

int solve(int H, int W, vector<string>& s) {
    // fprintf(stderr, "H=%d, W=%d\n", H, W);
    vector<int> d(W);
    map<ii,int> r_prev;
    int best = max(H, W);

    for (int i=0; i<H-1; ++i) {
        // 順
        rep(c, W) {
            d[c] = (s[i][c] == s[i+1][c]);
        }
        vector<int> e(W-1, 0);
        rep(i, W-1) {
            e[i] = d[i] & d[i+1];
        }
        vector<ii> r0 = ranges(W-1, e);
        // 逆
        rep(i, W) d[i] ^= 1;
        rep(i, W-1) {
            e[i] = d[i] & d[i+1];
        }
        // vector<ii> r1 = rev_ranges(W-1, r0);
        vector<ii> r1 = ranges(W-1, e);

#ifdef DEBUG
        cerr << i << ") " << r_prev << endl;
        cerr << "  + " << r0 << endl;
        cerr << "  + " << r1 << endl;
#endif
        for (ii p : r0) {
            best = max(best, 2 * (p.second - p.first + 1));
        }
        for (ii p : r1) {
            best = max(best, 2 * (p.second - p.first + 1));
        }

        map<ii,int> r_next;
        append_range(r_next, r_prev, r0);
        append_range(r_next, r_prev, r1);
#ifdef DEBUG
        cerr << " => " << r_next << endl;
#endif

        r_prev = r_next;

        for (auto p : r_prev) {
            ii x = p.first;
            int ph = p.second;
            best = max(best, (ph+1) * (x.second - x.first + 1));
        }

    }

    return best;
}

int main() {
    int H, W; cin >> H >> W;
    vector<string> s(H);
    rep(i, H) cin >> s[i];
    cout << solve(H,W,s) << endl;
    return 0;
}


Measured memory_bytes: 6656