#include <bits/stdc++.h>
using namespace std;
int n, m;
string grid[105];
int check_bomb(int i, int j) {
  if ((i > 0 && grid[i - 1][j] == '*') ||
      (i < n - 1 && grid[i + 1][j] == '*') ||
      (j > 0 && grid[i][j - 1] == '*') ||
      (j < m - 1 && grid[i][j + 1] == '*') ||
      (i > 0 && j > 0 && grid[i - 1][j - 1] == '*') ||
      (i > 0 && j < m - 1 && grid[i - 1][j + 1] == '*') ||
      (i < n - 1 && j > 0 && grid[i + 1][j - 1] == '*') ||
      (i < n - 1 && j < m - 1 && grid[i + 1][j + 1] == '*')) {
    printf("NO");
    return 1;
  }
  return 0;
}
int count_bomb(int i, int j) {
  int k = grid[i][j] - 48;
  int cnt = 0;
  if (i > 0 && grid[i - 1][j] == '*') cnt++;
  if (i < n - 1 && grid[i + 1][j] == '*') cnt++;
  if (j > 0 && grid[i][j - 1] == '*') cnt++;
  if (j < m - 1 && grid[i][j + 1] == '*') cnt++;
  if (i > 0 && j > 0 && grid[i - 1][j - 1] == '*') cnt++;
  if (i > 0 && j < m - 1 && grid[i - 1][j + 1] == '*') cnt++;
  if (i < n - 1 && j > 0 && grid[i + 1][j - 1] == '*') cnt++;
  if (i < n - 1 && j < m - 1 && grid[i + 1][j + 1] == '*') cnt++;
  if (cnt != k) {
    printf("NO");
    return 1;
  }
  return 0;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    cin >> grid[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] == '.') {
        int check = check_bomb(i, j);
        if (check == 1) return 0;
      } else if (grid[i][j] >= '1' && grid[i][j] <= '9') {
        int bomb = count_bomb(i, j);
        if (bomb == 1) return 0;
      }
    }
  }
  printf("YES");
  return 0;
}
