#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define chr unsigned char
#define maxn 100

int a[maxn][maxn];
int sum[maxn][maxn];
int cnt[maxn][maxn][5];

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

    int n, m;
    cin >> n >> m;

    chr x;
    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= m; ++j){
            cin >> x;
            a[i][j] = a[i + n][j] = a[i][j + m] = a[i + n][j + m] = x == '2';
        }
    }

    for (int i = 1; i < 2 * n; ++i){
        for (int j = 1; j < 2 * m; ++j){
            sum[i][j] = a[i][j] + a[i + 1][j] + a[i][j + 1] + a[i + 1][j + 1];
       //     cout << sum[i][j];
        }
      //  cout << endl;
    }

    for (int i = 0; i <= 2 * n; ++i){
        for (int j = 0; j <= 2 * m; ++j)
            for (int c = 0; c <= 4; ++c)
                cnt[i][j][c] = 0;
    }

    for (int i = 1; i < 2 * n; ++i)
        for (int j = 1; j < 2 * m; ++j)
            for (int c = 0; c <= 4; ++c){
        cnt[i][j][c] = cnt[i - 1][j][c] + cnt[i][j - 1][c] - cnt[i - 1][j - 1][c] +
                        (sum[i][j] == c ? 1 : 0);
            }

  /*  for (int i = 1; i <= 2 * n; ++i){
        for (int j = 1; j <= 2 * m; ++j)
            cout << cnt[i][j][2] << ' ';
        cout << endl;
    } */

    int ans = 0, s04, x1, x2, y1, y2;
    for (int i = n + 1; i <= 2 * n; ++i)
    for (int j = m + 1; j <= 2 * m; ++j){
        x1 = i - n + 1;
        x2 = i - 1;
        y1 = j - m + 1;
        y2 = j - 1;
        s04 = 0;
        for (int c = 0; c <= 4; c += 4){
            s04 += cnt[x2][y2][c] - cnt[x2][y1 - 1][c] - cnt[x1 - 1][y2][c]
                    + cnt[x1 - 1][y1 - 1][c];
        }

        ans = max(ans, s04);
    }

    cout << ans << endl;

    fclose(stdout);
    return 0;
}






