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+N} def calc(M): if M in memo: return memo[M] if M < 0: return 0 res = N * calc((M-1)//2) + calc(M//2) res %= mod memo[M] = res return res print(calc(M))