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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int sign(int x) { return (x > 0) - (x < 0); }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const deque<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const set<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

struct rolling_hash {
    using ull = unsigned long long;
    static constexpr ull MASK30 = (1ULL << 30) - 1;
    static constexpr ull MASK31 = (1ULL << 31) - 1;
    static constexpr ull MOD = (1ULL << 61) - 1;
    static constexpr ull POSITIVIZER = MOD << 2;
    static std::vector<ull> pow_base;
    int n;
    std::vector<ull> hash;
    static void push_pow(int n) {
        while (pow_base.size() <= n) { pow_base.push_back(calc_mod(mul(pow_base.back(), pow_base[1]))); }
    }
    static ull rng() {
        std::random_device rd;
        return std::uniform_int_distribution<ull>(MOD >> 1, MOD - 1)(rd);
    }
    static ull mul(ull a, ull b) {
        ull au = a >> 31;
        ull ad = a & MASK31;
        ull bu = b >> 31;
        ull bd = b & MASK31;
        ull mid = ad * bu + au * bd;
        return (au * bu << 1) + (mid >> 30) + ((mid & MASK30) << 31) + ad * bd;
    }
    static ull calc_mod(ull val) {
        val = (val & MOD) + (val >> 61);
        if (val >= MOD) { val -= MOD; }
        return val;
    }
    static ull connect(ull lhs, ull rhs, int rn) {
        push_pow(rn);
        return calc_mod(mul(lhs, pow_base[rn]) + rhs);
    }
    template<typename T> rolling_hash(const std::vector<T> &src) : n(src.size()), hash(n + 1) {
        for (int i = 0; i < src.size(); i++) { hash[i + 1] = calc_mod(mul(hash[i], pow_base[1]) + src[i]); }
        push_pow(n);
    }
    ull get_hash(int l, int r) const { return calc_mod(POSITIVIZER - mul(hash[l], pow_base[r - l]) + hash[r]); }
};
std::vector<rolling_hash::ull> rolling_hash::pow_base{1, rng()};

template<typename T>
int largest_rectangle(vector<T> height) {
    stack<int> st;
    height.push_back(0);
    vector<int> left(height.size());
    int ret = 0;
    for (int i = 0; i < height.size(); i++) {
        while (!st.empty() && height[st.top()] >= height[i]) {
            ret = max(ret, (i - left[st.top()]) * height[st.top()]);
            st.pop();
        }
        left[i] = st.empty() ? -1 : st.top();
        st.emplace(i);
    }
    return (ret);
}

template<typename F> long long discrete_binary_search(long long ok, long long ng, F is_ok) {
    while (abs(ok - ng) > 1) {
        long long mid = (ok + ng) / 2;
        (is_ok(mid) ? ok : ng) = mid;
    }
    return ok;
}

int H, W;
string S[2200], R[2200];
vector<char> Sv[2200], Rv[2200];
signed main() {
    cin >> H >> W;
    vector<rolling_hash> Sh, Rh;
    rep(i, H) {
        cin >> S[i], R[i] = S[i];
        rep(j, W) { R[i][j] = '.' + '#' - R[i][j]; }
        Sv[i] = vector<char>(all(S[i])), Rv[i] = vector<char>(all(R[i]));
        Sh.emplace_back(rolling_hash(Sv[i])), Rh.emplace_back(rolling_hash(Rv[i]));
    }
    int ans = W;
    rep(i, W) {
        vint h;
        rep(j, H - 1) {
            h.emplace_back(discrete_binary_search(i + 1, W + 1, [&](int x) {
                return Sh[j].get_hash(i, x) == Sh[j + 1].get_hash(i, x)
                    || Sh[j].get_hash(i, x) == Rh[j + 1].get_hash(i, x);
            }) - i);
        }
        chmax(ans, largest_rectangle(h));
    }
    cout << ans << endl;
}


Measured memory_bytes: 86028