#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>

using namespace std;

int s[1001][1001];

bool g[1000][1000];

int main() {
    freopen("video.in", "r", stdin);
    freopen("video.out", "w", stdout);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            char a;
            cin >> a;
            s[i][j] = a;
        }
        s[i][m] = s[i][0];
    }
    for (int i = 0; i <= m; i++) {
        s[n][i] = s[0][i];
    }
    int k = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i][j] == s[i + 1][j] && s[i][j] == s[i][j + 1] && s[i][j] == s[i + 1][j + 1]) {
                g[i][j] = 1;
                k++;
            }
        }
    }
    int c = 0, a, b;
    for (int i = 0; i < n; i++) {
        a = 0;
        for (int j = 0; j < m; j++) {
            a += g[i][j];
        }
        for (int j = 0; j < m; j++) {
            b = -g[i][j];
            for (int l = 0; l < n; l++) {
                b += g[l][j];
            }
            if (k - a - b > c) {
                c = k - a - b;
            }
        }
    }
    cout << c;
}
