#include <bits/stdc++.h>
using namespace std;
long long n, m, i = 0, j = 0, x = 0, cnt;
char a[105][105];
int main(void) {
  for (cin >> n >> m; i < n; i++) {
    for (j = 0; j < m; j++) cin >> a[i][j];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (a[i][j] == '*')
        continue;
      else if (a[i][j] == '.')
        cnt = 0;
      else
        cnt = a[i][j] - '0';
      x = 0;
      if (i - 1 >= 0 && a[i - 1][j] == '*') x++;
      if (i + 1 < n && a[i + 1][j] == '*') x++;
      if (j - 1 >= 0 && a[i][j - 1] == '*') x++;
      if (j + 1 < m && a[i][j + 1] == '*') x++;
      if (j - 1 >= 0 && i - 1 >= 0 && a[i - 1][j - 1] == '*') x++;
      if (j + 1 < m && i - 1 >= 0 && a[i - 1][j + 1] == '*') x++;
      if (j - 1 >= 0 && i + 1 < n && a[i + 1][j - 1] == '*') x++;
      if (j + 1 < m && i + 1 < n && a[i + 1][j + 1] == '*') x++;
      if (cnt == x)
        continue;
      else
        return cout << "NO", 0;
    }
  }
  cout << "YES";
  return 0;
}
