#include <bits/stdc++.h>
using namespace std;
char a[105][105];
int n, m;
int pan(int x, int y) {
  if (x >= 0 && x < n && y >= 0 && y < m)
    return 1;
  else
    return 0;
}
int judge(int k, int x, int y) {
  int ans = 0;
  if (x - 1 >= 0)
    if (a[x - 1][y] == '*') ans++;
  if (y - 1 >= 0)
    if (a[x][y - 1] == '*') ans++;
  if (x + 1 < n)
    if (a[x + 1][y] == '*') ans++;
  if (y + 1 < m)
    if (a[x][y + 1] == '*') ans++;
  if (pan(x - 1, y - 1))
    if (a[x - 1][y - 1] == '*') ans++;
  if (pan(x - 1, y + 1))
    if (a[x - 1][y + 1] == '*') ans++;
  if (pan(x + 1, y - 1))
    if (a[x + 1][y - 1] == '*') ans++;
  if (pan(x + 1, y + 1))
    if (a[x + 1][y + 1] == '*') ans++;
  if (ans == k)
    return 0;
  else
    return 1;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 0; i < n; i++) scanf("%s", a[i]);
    int flag = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (a[i][j] >= '0' && a[i][j] <= '9')
          flag = judge(a[i][j] - '0', i, j);
        else if (a[i][j] == '.')
          flag = judge(0, i, j);
        if (flag) break;
      }
      if (flag) break;
    }
    if (!flag)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
