#include <bits/stdc++.h>
using namespace std;
char arr[205][205];
int x[] = {1, -1, 1, -1, 1, -1, 0, 0};
int y[] = {0, 0, 1, 1, -1, -1, 1, -1};
int main() {
  int n, m;
  cin >> n >> m;
  memset(arr, 0, sizeof arr);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> arr[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (arr[i][j] == '*') continue;
      int cnt = 0;
      for (int k = 0; k < 8; k++)
        if (arr[i + x[k]][j + y[k]] == '*') cnt++;
      if (arr[i][j] == '.' && cnt != 0) {
        cout << "NO\n";
        return 0;
      } else if (arr[i][j] != '.' && cnt != arr[i][j] - '0') {
        cout << "NO\n";
        return 0;
      }
    }
  cout << "YES\n";
}
