#include <bits/stdc++.h>
using namespace std;
char b[100][100];
int dr[8] = {1, 1, 1, 0, 0, -1, -1, -1};
int dc[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> b[i][j];
  bool pos = 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (b[i][j] == '*') continue;
      int cnt = 0;
      for (int d = 0; d < 8; d++) {
        int tr = i + dr[d], tc = j + dc[d];
        if (tr < 0 || tc < 0 || tr >= n || tc >= m) continue;
        if (b[tr][tc] == '*') cnt++;
      }
      if (cnt == 0) {
        if (b[i][j] != '.') pos = 0;
      } else {
        cnt--;
        if (b[i][j] != ('1' + cnt)) pos = 0;
      }
    }
  if (pos)
    cout << "YES";
  else
    cout << "NO";
  cin >> n;
}
