#include<bits/stdc++.h>
#define reg register
#define For(i,a,b) for(reg int i=(a),i##END=(b);i<=i##END;i++)
#define Rof(i,b,a) for(reg int i=(b),i##END=(a);i>=i##END;i--)
#define go(u) for(reg int i=head[u];i;i=nxt[i])
#define int long long
using namespace std;
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    return x*f;
}
const int N=5e3+10,p=998244353;
int a[N],b[N];
signed main(){
	int n=read(),m=read();
	a[0]=1;For(i,1,n)a[i]=a[i-1]*m%p;
	For(x,1,m-1){
		int t=1;For(i,1,N-10)(t*=x)%=p,(b[i]+=t)%=p;
	}
	b[0]=m;
	int ans=a[n]*n%p;
//	cout<<ans<<endl;
	For(i,1,n)For(j,i+1,n){
		(ans-=a[n-(j-i)-1]*b[(j-i)-1]%p)%=p;
	}
	cout<<(ans+p)%p<<endl;
	return 0;
}
#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include "bits/stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define int long long int
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii>   vii;
//typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update>
//    ost;
#define rep(i,l,r)   for (int i = (l); i < (r); i++)
#define here cout << " Hey!!\n";
#define  pb push_back
#define  F  first
#define  S  second
#define all(v) (v).begin(),(v).end()
#define sz(a) (int)((a).size())
#define sq(x) ((x)*(x))
template <typename T>
void etch(T V) {
    for (auto x : V)    cout << x << ' ' ;
    cout << '\n';
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int N = 2e5+5;
const int INF = 1000111000111000111LL;
const ld EPS = 1e-12;
const ld PI = 3.141592653589793116;

int dp[55][2], n, p;
vi ans, v;

int solve(int i, int j)
{
    if (dp[i][j] != -1) {
        return dp[i][j];
    }
    if (i == n-1) {
        return (dp[i][j] = 1);
    }
    int lim = v[i+1]/v[i];
    int cur = ans[i] + j;
    if (cur == lim) {
        dp[i][j] = solve(i+1, 1);
        return dp[i][j];
    }
    if (cur) {
        dp[i][j] = solve(i+1, 0) + solve(i+1, 1);
    } else {
        dp[i][j] = solve(i+1, 0);
    }
    return dp[i][j];
}

int32_t main()
{
    SYNC
    cin >> n >> p;
    v.resize(n);
    rep(i,0,n) {
        cin >> v[i];
    }
    for (int i = n-1; i >=0 ;i--) {
        ans.pb(p/v[i]);
        p %= v[i];
    }
    reverse(all(ans));
    // etch(ans);
    memset(dp, -1, sizeof dp);
    cout << solve(0, 0);
    return 0;
}