#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;


using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int to[400001], ne[400001], he[200001];
int Q[200001], pl[200001], dl[200001];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N, K;
	cin >> N >> K;
	int k = 1;
	rep(i, N - 1) {
		int u, v;
		cin >> u >> v;
		to[k] = v;
		ne[k] = he[u];
		he[u] = k++;
		to[k] = u;
		ne[k] = he[v];
		he[v] = k++;
	}

	int q = 0, p = 0;
	Q[q++] = 1;
	while (p < N) {
		int u = Q[p++];
		int tmp = 0;
		int ind = he[u];
		he[u] = 0;
		while (ind) {
			int v = to[ind];
			tmp = ne[ind];
			if (he[v] > 0) {
				Q[q++] = v;
				ne[ind] = he[u];
				he[u] = -ind;
			}
			ind = tmp;
		}
	}

	int are = 1000000, pd0 = are;
	int L = 0, R = (N + K - 1) / K;
	while (L + 1 < R) {
		int wj = (L + R) / 2;

		int num = 0;

		for (int i = N - 1; i >= 0; i--) {
			int po = pd0 - 1;
			int dd = pd0;
			int u = Q[i];
			for (int ind = -he[u]; ind; ind = -ne[ind]) {
				int v = to[ind];
				if (po < pl[v]) po = pl[v];
				if (dd < dl[v]) dd = dl[v];
			}
			if (po >= dd) dd = 0;
			if (dd >= pd0 + wj) {
				num++;
				po = pd0 + wj;
				dd = 0;
			}
			pl[u] = po - 1;
			dl[u] = dd + 1;
		}

		int are = num + (dl[1] > pd0);
		if (are > K) L = wj;
		else R = wj;

		pd0 += are;
	}

	co(R);

	Would you please return 0;
}
#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <vector>
#include <queue>
#define lowbit(x) ((x) & (-(x)))
typedef long long ll;
#define For(i , a , b) for(ll i = a ; i <= b ; i ++)
#define FoR(i , a , b) for(ll i = a ; i >= b ; i --)
ll MIN(ll x, ll y) { return x < y ? x : y; }
ll MAX(ll x, ll y) { return x > y ? x : y; }
const ll MAXN = 523;
const ll MO = 998244353;
using namespace std;
 
ll H , W;
char mp[MAXN][MAXN];
char col[MAXN << 1 | 1];
int ans;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
	cin >> H >> W;
	For (i , 1 , H)
		cin >> (mp[i] + 1);
	For (i , 1 , H)
		For (j , 1 , W) {
			const char &w = mp[i][j];
			if (w == '.')
				continue;
			if (!col[i + j])
				col[i + j] = w;
			else {
				if (col[i + j] != w) {
					printf ("0\n");
					return 0;
				}
			}
		}
	ans = 1;
	For (i , 2 , H + W)
		if (!col[i])
			ans = (ans * 2) % MO;
	printf ("%lld\n" , ans);
    return 0;
}