#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, a[102][102], k;
  char c;
  cin >> n >> m;
  for (i = 0; i <= n + 1; i++)
    for (j = 0; j <= m + 1; j++) {
      if (i == 0 || i == n + 1 || j == 0 || j == m + 1)
        a[i][j] = -1;
      else {
        cin >> c;
        if (c == '.')
          a[i][j] = 0;
        else if (c == '*')
          a[i][j] = 9;
        else
          a[i][j] = ((int)c) - 48;
      }
    }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      if (a[i][j] != 9) {
        k = 0;
        if (a[i - 1][j] == 9) k++;
        if (a[i][j + 1] == 9) k++;
        if (a[i - 1][j + 1] == 9) k++;
        if (a[i + 1][j + 1] == 9) k++;
        if (a[i + 1][j - 1] == 9) k++;
        if (a[i][j - 1] == 9) k++;
        if (a[i - 1][j - 1] == 9) k++;
        if (a[i + 1][j] == 9) k++;
        if (k != a[i][j]) {
          cout << "NO";
          return 0;
        }
      }
    }
  cout << "YES";
  return 0;
}
