main :: IO ()
main = do
    [n, k] <- fmap read . words <$> getLine
    answer $ solve n k

type Answer = Int
answer :: Answer -> IO ()
answer = print

solve :: Int -> Int -> Answer
solve n k = 5 * ndiv + length (takeWhile (nmod + head is - 3 >=) is)
  where
    (ndiv, nmod) = (n - head is + 1) `divMod` 11
    f (i, j) = 9 * (7 * i + j + 1) `mod` 11
    is = fst <$> filter ((k ==) . f) [(i, j) | i <- [1 ..], j <- [1 .. 5]]

