#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],ans,f[20][131072]; const ll INF=1ll << 60; char s[MAXN]; 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) return 0*puts("1"); int o=1 << m; for (int i=0;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]); } for (int i=0;i>(m-1))) upd(ans,f[m][i]); printf("%lld\n",ans); return 0; }