/* はやく人間になりたい */
/* 人権を得たい */
/* nullmineralが書きましたが */
/* 責任はまったくとりません */

#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;

typedef long long int64;

bool same(char a, char b)
{
	return a == b || a == '?' || b == '?';
}

int main()
{
	const int mod = 100000;

	int h, w;
	char fld[32][32];
	
	int ans = 1;
	
	scanf("%d%d", &h, &w);
	for(int i = 0; i < h; ++i) {
		scanf("%s", fld[i]);
		for(int j = 0; j < w; ++j) {
			if(fld[i][j] == '?')
				ans = ans * 3 % mod;
		}
	}
	
	static int dp[2][3][1 << 20] = {0};
	int (*prev)[1 << 20] = dp[0];
	int (*cur)[1 << 20] = dp[1];
	int sum;
	char mapping[] = "JOI";
	
	for(int y = 0; y < h; ++y) {
		for(int x = 0; x < w; ++x) {
		
			sum = 0;
		
			if(y == 0 && x == 0) {
			
				for(int c = 0; c < 3; ++c) {
					prev[c][0] = same(mapping[c], fld[y][x]);
					sum += prev[c][0];
				}
				continue;
			}
			
			memset(*cur, 0, (3 * (1 << 20)));
			
			for(int i = 0; i < 3; ++i)
				for(int j = 0; j < (1 << w); ++j)
					cur[i][j] = 0;
		
			if(same(mapping[0], fld[y][x])) {
				for(int bit = 0; bit < (1 << w); bit += 2) {
			
					int &at = cur[0][bit];
					at = 0;
					
					at += prev[0][(bit >> 1)];
					at += prev[0][(bit >> 1) | (1 << (w - 1))];
					at += prev[1][(bit >> 1)];
					at += prev[1][(bit >> 1) | (1 << (w - 1))];
					at += prev[2][(bit >> 1)];
					at += prev[2][(bit >> 1) | (1 << (w - 1))];
			
					at = at % mod;
					sum = (sum + at) % mod;
				}
			}
			
			if(same(mapping[2], fld[y][x])) {
				for(int bit = 0; bit < (1 << (w - 1)); bit += 2) {
			
					int &at = cur[2][bit];
					at = 0;
					
					at += prev[0][(bit >> 1)];
					at += prev[0][(bit >> 1) | (1 << (w - 1))];
					at += prev[1][(bit >> 1)];
					at += prev[1][(bit >> 1) | (1 << (w - 1))];
					at += prev[2][(bit >> 1)];
					at += prev[2][(bit >> 1) | (1 << (w - 1))];
			
					at = at % mod;
					sum = (sum + at) % mod;
				}
			}
			
			if(same(mapping[1], fld[y][x])) {
			
				if(x == 0) {
					
					for(int bit = 0; bit < (1 << w); bit += 2) {
			
						int &at = cur[1][bit];
						at = 0;
					
						at += prev[0][(bit >> 1)];
						at += prev[0][(bit >> 1) | (1 << (w - 1))];
						at += prev[1][(bit >> 1)];
						at += prev[1][(bit >> 1) | (1 << (w - 1))];
						at += prev[2][(bit >> 1)];
						at += prev[2][(bit >> 1) | (1 << (w - 1))];
			
						at = at % mod;
						sum = (sum + at) % mod;
					}
					
				} else {
					
					for(int bit = 1; bit < (1 << w); bit += 2) {
			
						int &at = cur[1][bit];
						at = 0;
					
						at += prev[0][(bit >> 1)];
						at += prev[0][(bit >> 1) | (1 << (w - 1))];
			
						at = at % mod;
						sum = (sum + at) % mod;
					}
					
					for(int bit = 0; bit < (1 << w); bit += 2) {
			
						int &at = cur[1][bit];
						at = 0;
					
						at += prev[1][(bit >> 1)];
						at += prev[1][(bit >> 1) | (1 << (w - 1))];
						at += prev[2][(bit >> 1)];
						at += prev[2][(bit >> 1) | (1 << (w - 1))];
			
						at = at % mod;
						sum = (sum + at) % mod;
					}
				}
			}		
			
			swap(prev, cur);
		}
	}
	
	//printf("[Debug] sum : %d, ans : %d\n", sum, ans);
	
	ans = (ans + mod - sum) % mod;
	
	printf("%d\n", ans);	
	
	return 0;
}

Measured memory_bytes: 25776