#include <cstdio>
#include <algorithm>
#include <vector>
#include <climits>
#include <cstring>
#include <bitset>

#define f first
#define s second
#define pb push_back
#define NMAX 100000
#define pii pair <int, int>

using namespace std;

int n, m, v[512][512], up[512][512], st[512][512], dw[512][512];
char str[512];

int main ()
{
    //freopen ("file.in", "r", stdin);

    int n, m;
    scanf ("%d %d\n", &n, &m);

    for (int i = 1; i <= n; ++i)
    {
        gets (str);

        for (int j = 0; j < m; ++j)
            v[i][j + 1] = str[j] - 48;
    }

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
        {
            if (v[i][j])
            {
                up[i][j] = up[i - 1][j] + 1;
                if (!v[i - 1][j]) up[i][j] = 0;
                else if (!up[i - 1][j]) ++up[i][j];
            }

            if (v[i][j])
            {
                if (st[i][j - 1]) st[i][j] = st[i][j - 1] + 1;
                if (up[i][j - 1]) st[i][j] = max (st[i][j], up[i][j - 1] + 1);
            }
        }

    int rez = 0;
    for (int i = n; i; --i)
        for (int j = m; j; --j)
            if (v[i][j])
            {
                if (dw[i + 1][j]) dw[i][j] = dw[i + 1][j] + 1;
                if (st[i + 1][j]) dw[i][j] = max (dw[i][j], st[i + 1][j] + 1);

                rez = max (rez, dw[i][j]);
            }

    printf ("%d\n", rez);

    return 0;
}