#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
// ------------ Modulo Class ------------ //
template<unsigned mod>
class modulo {
private:
unsigned x;
public:
modulo() : x(0) {};
modulo(unsigned x_) : x(x_) {};
operator unsigned() { return x; }
modulo operator==(const modulo& m) const { return x == m.x; }
modulo operator!=(const modulo& m) const { return x != m.x; }
modulo& operator+=(const modulo& m) { x = (x + m.x >= mod ? x + m.x - mod : x + m.x); return *this; }
modulo& operator-=(const modulo& m) { x = (x < m.x ? x - m.x + mod : x - m.x); return *this; }
modulo& operator*=(const modulo& m) { x = 1ULL * x * m.x % mod; return *this; }
modulo operator+(const modulo& m) const { return modulo(*this) += m; }
modulo operator-(const modulo& m) const { return modulo(*this) -= m; }
modulo operator*(const modulo& m) const { return modulo(*this) *= m; }
};
// ------------ Matrix Functions ------------ //
typedef std::vector<modulo<mod> > matrix_base;
typedef std::vector<matrix_base> matrix;
matrix mul(const matrix& a, const matrix& b) {
assert(a[0].size() == b.size());
matrix ret(a.size(), matrix_base(b[0].size(), 0));
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < b[0].size(); j++) {
for (int k = 0; k < b.size(); k++) ret[i][j] += a[i][k] * b[k][j];
}
}
return ret;
}
matrix unit(int n) {
matrix ret(n, matrix_base(n, 0));
for (int i = 0; i < n; i++) ret[i][i] = 1;
return ret;
}
matrix power(const matrix& a, long long b) {
assert(a.size() == a[0].size());
matrix f = a, ret = unit(a.size());
while (b) {
if (b & 1) ret = mul(ret, f);
f = mul(f, f);
b >>= 1;
}
return ret;
}
int nth_fibonacci(long long x) {
matrix e(2, matrix_base(2));
e[0][0] = e[0][1] = e[1][0] = 1;
matrix p(2, matrix_base(1));
p[0][0] = 1; p[1][0] = 0;
return mul(power(e, x), p)[1][0];
}
int n; long long m;
int main() {
cin >> n >> m;
if(n > 3) return 0;
int ret = nth_fibonacci(m + (n - 1) * 2);
if(n == 2) ret = (ret - 1 + mod) % mod;
if(n == 3) ret = (ret - (m + 3) % mod + mod) % mod;
cout << ret << endl;
return 0;
}