MOD = 998244353 N,M = map(int,input().split()) bl = M.bit_length() B = [[0] * (bl + 1) for _ in range(bl+1)] B[0][0] = 1 for i in range(1,bl+1): for j in range(i+1): B[i][j] = B[i-1][j-1] + B[i-1][j] for i in range(bl+1): B[i][1] += 1 BT = [0] * (bl+1) k = 0 for i in reversed(range(bl+1)): if (M >> i) & 1: k += 1 for j in range(i+1): BT[j+k] += B[i][j+1] ans = 1 for i in range(bl+1): ans += BT[i] * pow(N,i,MOD) ans %= MOD print(ans)