#include<bits/stdc++.h>
#define pd push_back
#define all(A) A.begin(),A.end()
#define lb lower_bound
#define ve std::vector
typedef long long ll;
typedef long long ll;
typedef __int128 Int;
typedef unsigned long long ul;
typedef long double LD;
bool FileIfstream(std::string name){
std::ifstream f(name.c_str());
return f.good();
}
namespace Math{
ll QP(ll x,ll y,ll mod){ll ans=1;for(;y;y>>=1,x=x*x%mod)if(y&1)ans=ans*x%mod;return ans;}
ll inv(ll x,ll mod){return QP(x,mod-2,mod);}
}
const int N=2e5+10;
const int mod=998244353;
template<int n,int m>
struct Matrix{
int C[n][m];
Matrix<n,m>(){memset(C,0,sizeof(C));}
Matrix<n,m>(ve<ve<int>>v){
for(int i=0;i<n;i++)
for(int j=0;j<=m;j++)
C[i][j]=v[i][j];
}
auto operator [](int i)const{return C[i];};
auto& operator [](int i){return C[i];}
template<int k>
Matrix<n,k> operator *(Matrix<m,k>P){
Matrix<n,k> ans;
for(int i=0;i<n;i++)
for(int j=0;j<k;j++)
for(int c=0;c<m;c++)
ans[i][j]=(ans[i][j]+1ll*C[i][c]*P[c][j]%mod)%mod;
return ans;
}
Matrix<n,n> operator ^(ll y){
Matrix<n,n>ans;assert(n==m);
for(int i=0;i<n;i++)ans[i][i]=1;
Matrix<n,n>x=(*this);
for(;y;x=x*x,y>>=1)
if(y&1)ans=ans*x;
return ans;
}
};
void solve(){
//don't forget to open long long
int n,m;std::cin>>n>>m;
Matrix<3,3>Base({{0,1,1},
{1,0,0},
{0,1,0}});
Matrix<3,3>V=Base^n;
std::map<int,int>mp;
auto dfs=[&](int x,auto self)->int{
if(!x)return 1;if(mp.count(x))return mp[x];
int &p=mp[x];
if(x==1)return p=(0ll+V[0][0]+V[1][1]+V[2][2])%mod;
if(x&1^1)return p=(self(x/2,self)+self(x/2-1,self))%mod;
return p=1ll*self(x/2,self)*(0ll+V[0][0]+V[1][1]+V[2][2])%mod;
};
std::cout<<dfs(m,dfs)<<'\n';
}
int main(){
#ifndef ONLINE_JUDGE
if(!FileIfstream("IO.in")){
freopen("IO.in","w",stdout);
return 0;
}
freopen("IO.in","r",stdin);
freopen("IO.out","w",stdout);
#endif
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int T=1;
//std::cin>>T;
while(T--)solve();
#ifndef ONLINE_JUDGE
std::cerr<<std::fixed<<std::setprecision(10)<<1.0*clock()/CLOCKS_PER_SEC<<'\n';
#endif
return 0;
}