#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const int maxn = 105;
int maze[maxn][maxn];
int dr[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int dc[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int main() {
  std::ios::sync_with_stdio(false);
  int n, m;
  while (cin >> n >> m) {
    for (int i = 0; i < n; i++) {
      for (int k = 0; k < m; k++) {
        char c;
        cin >> c;
        if (c == '.')
          maze[i][k] = 0;
        else if (c == '*')
          maze[i][k] = INF;
        else
          maze[i][k] = c - '0';
      }
    }
    bool flag = false;
    for (int i = 0; i < n; i++) {
      for (int k = 0; k < m; k++) {
        if (maze[i][k] == INF) {
          for (int t = 0; t < 8; t++) {
            int r = i + dr[t];
            int c = k + dc[t];
            if (r >= 0 && r < n && c >= 0 && c < m && maze[r][c] != INF) {
              maze[r][c] -= 1;
            }
          }
        }
      }
    }
    for (int i = 0; i < n; i++) {
      for (int k = 0; k < m; k++) {
        if (maze[i][k] == INF || maze[i][k] == 0) continue;
        flag = true;
        break;
      }
    }
    if (flag)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
}
