The bishop can go to 4 directions (diagonally).
The number of cells in the upper-left direction (the bishop can attack) is: min( x-1, y-1 )
The number of cells in the lower-left direction (the bishop can attack) is: min( x-1, M-y )
The number of cells in the upper-right direction (the bishop can attack) is: min( N-x, y-1 )
The number of cells in the lower-right direction (the bishop can attack) is: min( N-x, M-y )
So the total number of cells (the bishop can attack) is min( x-1, y-1 ) + min( x-1, M-y ) + min( N-x, y-1 ) + min( N-x, M-y ) + 1