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