#include <bits/stdc++.h>
using namespace std;
bool check(vector<vector<char>> &board, int n, int m) {
  vector<vector<int>> d = {{0, 1}, {1, 0},  {0, -1}, {-1, 0},
                           {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      int sum = 0;
      for (int k = 0; k < 8; ++k) {
        int ny = i + d[k][0];
        int nx = j + d[k][1];
        if (ny >= 0 && ny < n && nx >= 0 && nx < m && board[ny][nx] == '*')
          sum++;
      };
      if (board[i][j] == '*') continue;
      if (board[i][j] == '.' && sum != 0)
        return false;
      else if (board[i][j] != '.') {
        int v = (int)board[i][j] - 48;
        if (v != sum) return false;
      }
    };
  return true;
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<char>> board(n, vector<char>(m));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> board[i][j];
  bool ans = check(board, n, m);
  if (ans)
    printf("YES\n");
  else
    printf("NO\n");
}
