#include <bits/stdc++.h>
using namespace std;
int n, m;
char g[105][105];
bool judge1(int k, int i, int j) {
  int ans = 0;
  if (i == 0 && j == 0) {
    if (g[0][1] == '*') ans++;
    if (g[1][1] == '*') ans++;
    if (g[1][0] == '*') ans++;
  } else if (i == 0 && j == m - 1) {
    if (g[i][j - 1] == '*') ans++;
    if (g[i + 1][j - 1] == '*') ans++;
    if (g[i + 1][j] == '*') ans++;
  } else if (i == n - 1 && j == 0) {
    if (g[i - 1][j] == '*') ans++;
    if (g[i][j + 1] == '*') ans++;
    if (g[i - 1][j + 1] == '*') ans++;
  } else if (i == n - 1 && j == m - 1) {
    if (g[i][j - 1] == '*') ans++;
    if (g[i - 1][j] == '*') ans++;
    if (g[i - 1][j - 1] == '*') ans++;
  } else if (i == 0 && j != 0 && j != m - 1) {
    if (g[i][j - 1] == '*') ans++;
    if (g[i][j + 1] == '*') ans++;
    if (g[i + 1][j - 1] == '*') ans++;
    if (g[i + 1][j] == '*') ans++;
    if (g[i + 1][j + 1] == '*') ans++;
  } else if (i == n - 1 && j != 0 && j != m - 1) {
    if (g[i][j - 1] == '*') ans++;
    if (g[i][j + 1] == '*') ans++;
    if (g[i - 1][j - 1] == '*') ans++;
    if (g[i - 1][j] == '*') ans++;
    if (g[i - 1][j + 1] == '*') ans++;
  } else if (j == 0 && i != 0 && i != n - 1) {
    if (g[i - 1][j] == '*') ans++;
    if (g[i + 1][j] == '*') ans++;
    if (g[i - 1][j + 1] == '*') ans++;
    if (g[i][j + 1] == '*') ans++;
    if (g[i + 1][j + 1] == '*') ans++;
  } else if (j == m - 1 && i != 0 && i != n - 1) {
    if (g[i - 1][j - 1] == '*') ans++;
    if (g[i][j - 1] == '*') ans++;
    if (g[i + 1][j - 1] == '*') ans++;
    if (g[i - 1][j] == '*') ans++;
    if (g[i + 1][j] == '*') ans++;
  } else {
    for (int p = i - 1; p <= i + 1; p++) {
      for (int t = j - 1; t <= j + 1; t++) {
        if (g[p][t] == '*') ans++;
      }
    }
  }
  if (ans == k) return true;
  return false;
}
int main() {
  int flag;
  while (scanf("%d%d", &n, &m) == 2) {
    flag = 0;
    memset(g, 0, sizeof(g));
    for (int i = 0; i < n; i++) {
      scanf("%s", g[i]);
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int p = 0;
        if (g[i][j] >= '0' && g[i][j] <= '9') {
          p = g[i][j] - '0';
        } else if (g[i][j] == '.') {
          p = 0;
        } else if (g[i][j] == '*')
          continue;
        if (!judge1(p, i, j)) {
          flag = 1;
          break;
        }
      }
    }
    if (!flag)
      printf("YES\n");
    else
      printf("NO\n");
  }
}
