#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5, oo = 1e9 + 10;
int n, m;
char ch[109][109];
int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
bool inside(int i, int j) { return i > -1 && j > -1 && i < n && j < m; }
int f(int x, int y) {
  int ret = 0;
  for (int i = 0; i < 8; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (inside(nx, ny) && ch[nx][ny] == '*') ret++;
  }
  return ret;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> ch[i][j];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (ch[i][j] == '*') continue;
      int tmp = ch[i][j] - '0';
      if (ch[i][j] == '.') {
        if (f(i, j) != 0) {
          cout << "NO\n";
          ;
          return 0;
        }
      } else if (tmp != f(i, j)) {
        cout << "NO\n";
        return 0;
      }
    }
  }
  cout << "YES\n";
  return 0;
}
