import sys,random,bisect from collections import deque,defaultdict,Counter from heapq import heapify,heappop,heappush from itertools import cycle, permutations from math import log,gcd input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) mod = 998244353 N,M = mi() memo = {0:[1],1:[1,1]} def calc(M): if M in memo: return memo[M] if M < 0: return [0] res = [0] * 30 A = calc((M-1)//2) for i in range(len(A)): if A[i]: res[i+1] += A[i] res[i+1] %= mod B = calc(M//2) for i in range(len(B)): res[i] += B[i] res[i] %= mod memo[M] = res return res cnt = calc(M) res = 0 for k in range(len(cnt)): res += pow(N,k,mod) * cnt[k] % mod res %= mod print(res)