#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int main(int argc, char *argv[]) {
  int h, w;
  cin >> h >> w;
  std::vector<string> mps(h);
  for (int i = 0; i < h; i++) {
    cin >> mps[i];
  }
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (mps[y][x] == '*') continue;
      int cnt = 0;
      for (int k = 0; k < 8; k++) {
        int nx = x + dx[k];
        int ny = y + dy[k];
        if (0 <= nx && nx < w && 0 <= ny && ny < h) {
          if (mps[ny][nx] == '*') cnt++;
        }
      }
      if (cnt == 0 && mps[y][x] == '.') continue;
      if (cnt == (mps[y][x] - '0')) continue;
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
