#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int a[2000][2000];
int b[2000][2000];

inline int f(int i)
{
    return ((i & (i + 1)) - 1);
}

inline int g(int i)
{
    return (i | (i + 1));
}

void add(int x, int y)
{
    for (int i = x; i < 2000; i = g(i))
        for (int j = y; j < 2000; j = g(j))
            a[i][j]++;
}

int get (int x, int y)
{
    int ans = 0;
    for (int i = x; i >= 0; i = f(i))
        for (int j = y; j >= 0; j = f(j))
            ans += a[i][j];
    return ans;
}



int main()
{
    freopen("video.in", "r", stdin);
    freopen("video.out", "w", stdout);

    int n, m, f;
    char s;
    cin >> n >> m;
    scanf("%c", &s);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            scanf("%c", &s);
            f = s - '0';
            b[i][j] = f;
            b[i + n][j + m] = f;
            b[i + n][j] = f;
            b[i][j + m] = f;
        }
        scanf("%c", &s);
    }

    for (int i = 0; i < 2 * n - 1; i++)
        for (int j = 0; j < 2 * m - 1; j++)
            if ((b[i][j] == b[i + 1][j]) && (b[i][j] == b[i + 1][j + 1]) && (b[i][j] == b[i][j + 1]))
            {
                //cout << "add "<< i << " "<< j << endl;
                add(i, j);
            }
    int maxi = 0;
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= m; j++)
        {
            int ans = get(i + n - 2, j + m - 2) - get(i - 1, j + m - 2) - get(i + n - 2, j - 1) + get(i - 1, j - 1);
            maxi = max(maxi, ans);
        }
    cout << maxi;
}
