#include <iostream>
using namespace std;
int r,c,dy=0,dn=0;
int a[15][15];
void detect1(int x,int y) {
if(x>0 && y>0) {
if(a[x-1][y-1] == 5) {
a[x][y] = 0;
a[x-1][y-1] = 0;
}
}
if(x>0) {
if(a[x-1][y] == 5) {
a[x][y] = 0;
a[x-1][y] = 0;
}
}
if(x>0 && y<c-1) {
if(a[x-1][y+1] == 5) {
a[x][y] = 0;
a[x-1][y+1] = 0;
}
}
if(y>0) {
if(a[x][y-1] == 5) {
a[x][y] = 0;
a[x][y-1] = 0;
}
}
if(y<c-1) {
if(a[x][y+1] == 5) {
a[x][y] = 0;
a[x][y+1] = 0;
}
}
if(x<r-1 && y>0) {
if(a[x+1][y-1] == 5) {
a[x][y] = 0;
a[x+1][y-1] = 0;
}
}
if(x<r-1) {
if(a[x+1][y] == 5) {
a[x][y] = 0;
a[x+1][y] = 0;
}
}
if(x<r-1 && y<c-1) {
if(a[x+1][y+1] == 5) {
a[x][y] = 0;
a[x+1][y+1] = 0;
}
}
}
void detect2(int x,int y) {
if(x>0 && y>0) {
if(a[x-1][y-1] == 1) {
a[x-1][y-1] = 0;
dy++;
}
}
if(x>0) {
if(a[x-1][y] == 1) {
a[x-1][y] = 0;
dy++;
}
}
if(x>0 && y<c-1) {
if(a[x-1][y+1] == 1) {
a[x-1][y+1] = 0;
dy++;
}
}
if(y>0) {
if(a[x][y-1] == 1) {
a[x][y-1] = 0;
dy++;
}
}
if(y<c-1) {
if(a[x][y+1] == 1) {
a[x][y+1] = 0;
dy++;
}
}
if(x<r-1 && y>0) {
if(a[x+1][y-1] == 1) {
a[x+1][y-1] = 0;
dy++;
}
}
if(x<r-1) {
if(a[x+1][y] == 1) {
a[x+1][y] = 0;
dy++;
}
}
if(x<r-1 && y<c-1) {
if(a[x+1][y+1] == 1) {
a[x+1][y+1] = 0;
dy++;
}
}
}
int main() {
cin >> r >> c;
for(int i=0; i<r; i++) {
for(int j=0; j<c; j++) {
cin >> a[i][j];
}
}
for(int i=0; i<r; i++) {
for(int j=0; j<c; j++) {
if(a[i][j] == 5) {
detect1(i,j);
if(a[i][j] == 5) {
detect2(i,j);
}
}
}
}
for(int i=0; i<r; i++) {
for(int j=0; j<c; j++) {
if(a[i][j] == 1){
dn++;
}
}
}
cout << dy << ' ' << dn;
cout << endl;
return 0;
}