#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
string s[MAXN];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  int asdahjdhaskjdhkasfj;
  int asjbsadjhfdasfhk;
  int fdjhkxmnasdfkjhewui;
  int asfdjhkasjfdhakj;
  string askdhaskj;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int flag = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '.') {
        for (int x = -1; x <= 1; x++) {
          for (int y = -1; y <= 1; y++) {
            if (x == 0 && y == 0) continue;
            int nx = i + x, ny = j + y;
            if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
            if (s[nx][ny] == '*') {
              return puts("NO"), 0;
            }
          }
        }
      } else if (s[i][j] >= '1' && s[i][j] <= '8') {
        int counts = 0;
        for (int x = -1; x <= 1; x++) {
          for (int y = -1; y <= 1; y++) {
            if (x == 0 && y == 0) continue;
            int nx = i + x, ny = j + y;
            if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
            if (s[nx][ny] == '*') {
              counts++;
            }
          }
        }
        if (counts != (int)(s[i][j] - '0')) {
          return puts("NO"), 0;
        }
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}
