#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
const int MXN = 3e5 + 1;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const double PI = acos(-1.0);
int n, m;
char c[101][101];
int dx[] = {1, -1, 0, 0, +1, +1, -1, -1};
int dy[] = {0, 0, +1, -1, -1, +1, -1, +1};
bool isin(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= m; }
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> c[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (isdigit(c[i][j])) {
        bool kek = 0;
        int ans = 0;
        for (int k = 0; k < 8; k++) {
          if (isin(i + dx[k], j + dy[k]) && c[i + dx[k]][j + dy[k]] == '*') {
            ans++;
          }
        }
        if (ans != c[i][j] - '0') {
          cout << "NO";
          return 0;
        }
      } else if (c[i][j] == '.') {
        for (int k = 0; k < 8; k++) {
          if (isin(i + dx[k], j + dy[k]) && c[i + dx[k]][j + dy[k]] == '*') {
            cout << "NO";
            return 0;
          }
        }
      }
    }
  }
  cout << "YES";
  return 0;
}
