#include <bits/stdc++.h>
using namespace std;
int n, m;
char grid[110][110];
int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1};
int dy[8] = {0, 1, -1, 1, -1, 0, 1, -1};
bool valid(int i, int j) {
  if (i >= 0 && i < n && j >= 0 && j < m) return 1;
  return 0;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> grid[i][j];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] == '*') continue;
      int cnt = 0;
      for (int k = 0; k < 8; k++)
        if (valid(i + dx[k], j + dy[k]) && grid[i + dx[k]][j + dy[k]] == '*')
          cnt++;
      if (grid[i][j] == '.') {
        if (cnt) return 0 * printf("NO\n");
      } else if (grid[i][j] - '0' != cnt)
        return 0 * printf("NO\n");
    }
  }
  printf("YES\n");
}
