#include <bits/stdc++.h>
char mine[100][100];
bool validate(int i, int j, int bc, int r, int c) {
  bool lt = true;
  bool rt = true;
  bool dt = true;
  bool ut = true;
  int cnt = 0;
  if (i == 0) ut = false;
  if (i == r - 1) dt = false;
  if (j == c - 1) rt = false;
  if (j == 0) lt = false;
  if (lt) cnt = mine[i][j - 1] == '*' ? ++cnt : cnt;
  if (rt) cnt = mine[i][j + 1] == '*' ? ++cnt : cnt;
  if (ut) cnt = mine[i - 1][j] == '*' ? ++cnt : cnt;
  if (dt) cnt = mine[i + 1][j] == '*' ? ++cnt : cnt;
  if (lt && ut) cnt = mine[i - 1][j - 1] == '*' ? ++cnt : cnt;
  if (lt && dt) cnt = mine[i + 1][j - 1] == '*' ? ++cnt : cnt;
  if (rt && ut) cnt = mine[i - 1][j + 1] == '*' ? ++cnt : cnt;
  if (rt && dt) cnt = mine[i + 1][j + 1] == '*' ? ++cnt : cnt;
  if (bc == cnt)
    return true;
  else
    return false;
}
int main() {
  int r, c;
  std::cin >> r >> c;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) std::cin >> mine[i][j];
  }
  std::string ans = "YES";
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      if (mine[i][j] != '*') {
        int bc;
        if (mine[i][j] == '.')
          bc = 0;
        else
          bc = (int)mine[i][j] - 48;
        if (!validate(i, j, bc, r, c)) {
          ans = "NO";
          break;
        }
      }
    }
  }
  std::cout << ans << "\n";
  return 0;
}
