#include using namespace std; typedef long long ll; const int MM = 201712111; const int MAXN = 2000 + 10; int n, m; int a[MAXN][MAXN]; ll d[MAXN][MAXN]; const ll INF = 1ll << 60; char s[MAXN]; ll f[20][131072]; ll upd(ll &x, ll y){ x = (x + y) % MM; } int main(){ scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++){ scanf("%s", s + 1); for (int j = 1; j <= m; j++) a[i][j] = ((s[j] == '?') ? 0 : (s[j] - '0')); } if (m >= 18){ for (int i = 1; i <= m; i++) for (int j = i + 1; j <= m; j++) swap(a[i][j], a[j][i]); swap(n, m); } for (int i = 0; i <= n; i++) for (int j = 0; j <= m; j++) d[i][j] = INF; d[1][1] = (a[1][1] == 0) + a[1][1]; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (i != 1 || j != 1) d[i][j] = min(d[i-1][j], d[i][j-1]) + a[i][j] + (a[i][j] == 0); printf("%d\n", d[n][m]); if (m == 1){ puts("1"); return 0; } int o = 1 << m; for (int i = 0; i < o; i++) f[1][i] = 0; f[1][1] = 1; int oo = o - 1; for (int cnt = 2; cnt <= n * m; cnt++){ int x = (cnt - 1) / m + 1; int y = (cnt - 1) % m + 1; int py = (y == 1 ? m : y - 1); for (int i = 0; i < o; i++) f[y][i] = 0; if (a[x][y] == 0){ for (int i = 0; i < o; i++) if(f[py][i]){ if ((d[x-1][y]+1==d[x][y] && ((i >> (y - 1)) & 1)) || (d[x][y-1]+1==d[x][y] && ((i >> (y - 2)) & 1))) upd(f[y][i|(1<<(y-1))], f[py][i]), upd(f[y][i&(oo^(1<<(y-1)))], f[py][i]*8); else upd(f[y][i&(oo^(1<<(y-1)))], f[py][i]*9); } } else{ for (int i = 0; i < o; i++) if(f[py][i]){ if ((d[x-1][y]+a[x][y]==d[x][y] && ((i >> (y - 1)) & 1)) || (d[x][y-1]+a[x][y]==d[x][y] && ((i >> (y - 2)) & 1))) upd(f[y][i|(1<<(y-1))], f[py][i]); else upd(f[y][i&(oo^(1<<(y-1)))], f[py][i]); } } } ll ans = 0; for (int i = 0; i < o; i++) if ((i >> (m - 1))) upd(ans, f[m][i]); printf("%lld\n", ans); return 0; }