#include <stdio.h>
#include <stdlib.h>

using namespace std ;

int main()
{
    int n ; int m ; int j = 0 ; int i = 0 ;
    
    
    scanf("%d",&n);
    scanf("%d",&m);
    int matricaulaz[n][m] ;
    int rm [n+1][m] ;
    
    for ( j = 0 ; j < n ; j++ )
    {
        for ( i = 0 ; i < m ; i++ )
        {
            scanf("%d",&matricaulaz[n][m]);
            //printf("%d",matricaulaz[n][m]);
            rm[n+1][m]=0;
        }
    }
    
    for ( i = 0 ; i < m ; i++ )
    {
        rm[0][i] = 1 ;
    }
    
    int p1 = 0 ;
    int p2 = 0 ;
    int lr = 0 ;
    
    for ( i = 1 ; i < m+1 ; i++ )
    {
        for ( j = 0 ; j < n ; j++ )
        {
            if ( matricaulaz[i-1][j] == 1 )
            {
                rm[i][j]++ ;
            }
            else
            {
                rm[i][j] = 0 ;
                int li = -1 ;
                int di = -1 ;
                for ( p1 = j ; p1 >= 0 ; p1-- )
                {
                    if ( matricaulaz[i-1][p1] != 0 ) { li = p1 ; break ; }
                }
                
                for ( p1 = j ; p1 < m ; p1++ )
                {
                    if ( matricaulaz[i-1][p1] != 0 ) { di = p1 ; break ; }
                }
                
                if ( li == -1 ) { rm[i][di] ++ ; }
                else if ( di == -1 ) { rm[i][li] ++ ; }
                else
                {
                   
                }
                
            }
            
        }
    }
    
}