local mfl, mce = math.floor, math.ceil local function badd(a, b) return (a + b) % 2 end local function bmul(a, b) return a * b end local ffi = require("ffi") local C = ffi.C ffi.cdef[[ long long atoll(const char*); ]] local function lltonumber(str) return C.atoll(str) end local n, k = io.read():match("(%d+) (%d+)") n = tonumber(n) local strk = k k = lltonumber(k) local str = io.read() local dlim = 60 local mat = {} for i = 1, n - 1 do mat[i] = {} for j = 1, n do mat[i][j] = 1 + i == j and 1 or 0 end end mat[n] = {} for j = 1, n do mat[n][j] = 1 end local vec = {} for i = 1, dlim do vec[i] = {} end local a = {} do local i = 0 for w in str:gmatch("%d+") do i = i + 1 w = lltonumber(w) a[i] = w assert(w <= 1000000000000000000LL) for j = 1, dlim do vec[j][i] = w % 2LL == 0 and 0 or 1 w = w / 2LL end end end if #strk <= 3 then local tk = tonumber(strk) if tk <= n then print(a[tk]) os.exit() end end k = k - n local tmpmat = {} for i = 1, n do tmpmat[i] = {} end local tmpvec = {} local function matmat() for i = 1, n do for j = 1, n do local v = 0 for k = 1, n do v = badd(v, bmul(mat[i][k], mat[k][j])) end tmpmat[i][j] = v end end for i = 1, n do for j = 1, n do mat[i][j] = tmpmat[i][j] end end end local function matvec() for d = 1, dlim do for i = 1, n do local v = 0 for k = 1, n do v = badd(v, bmul(mat[i][k], vec[d][k])) end tmpvec[i] = v end for i = 1, n do vec[d][i] = tmpvec[i] end end end while 0LL < k do if k % 2LL == 1LL then matvec() end matmat() k = k / 2LL end local ret = 0LL local mul = 1LL for i = 1, dlim do if vec[i][n] == 1 then ret = ret + mul end mul = mul + mul end ret = tostring(ret):gsub("LL", "") print(ret)