#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
vector<string> vr;
int n, m;
int a[105][105], b[105][105];
int xx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int yy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
bool check(int i, int j) {
  if (i >= 0 && i < n && j >= 0 && j < m && a[i][j] != -2 && a[i][j] != -6)
    return true;
  return false;
}
bool Check(int i, int j) {
  if (i >= 0 && i < n && j >= 0 && j < m && b[i][j] == -6) return true;
  return false;
}
void dfs(int x, int y) {
  int X, Y, i;
  for (i = 0; i < 8; i++) {
    X = x + xx[i];
    Y = y + yy[i];
    if (check(X, Y)) b[X][Y]++;
  }
}
int main() {
  char ma[105][105];
  while (~scanf("%d%d", &n, &m)) {
    int f = 0;
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    for (int i = 0; i < n; i++) {
      cin >> ma[i];
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        a[i][j] = ma[i][j] - '0';
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (a[i][j] == -6) {
          b[i][j] = -6;
          dfs(i, j);
        }
        if (a[i][j] == -2) b[i][j] = -2;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (b[i][j] == -2) {
          for (int k = 0; k < 8; k++) {
            int X = xx[k] + i;
            int Y = yy[k] + j;
            if (Check(X, Y)) {
              f = 1;
              break;
            }
          }
        }
        if (a[i][j] != b[i][j]) {
          f = 1;
          break;
        }
        if (f == 1) break;
      }
      if (f == 1) break;
    }
    if (f)
      printf("NO\n");
    else
      printf("YES\n");
  }
  return 0;
}
