local function lltonumber(str) local ret = 0LL local sign = str:sub(1, 1) ~= "-" local begin = sign and 1 or 2 for i = begin, #str do ret = ret * 10LL ret = ret + tonumber(str:sub(i, i)) end if not sign then ret = ret * -1LL end return ret end local n = io.read("*n", "*l") local s = io.read() local a = 1 for ss in s:gmatch("%d+") do local p = lltonumber(ss) if p == 0LL then a = -1 break else p = p % 9LL local str = tostring(p):gsub("LL", "") local p32 = tonumber(str) a = (a * p32) % 9 end end if a == -1 then print(0) elseif a == 0 then print(9) else print(a) end