import Data.Char

main :: IO()
main = do
    n <- getLine
    s <- getLine :: IO String
    putStrLn $ show $ solve s

solve :: String -> Int
solve s =
    let
        nums = map (\x -> (fromEnum x) - (fromEnum '0')) s
    in
    cal nums
    
cal :: [Int] -> Int
cal [x] = x
cal (x:xs) = cal $ sub (x:xs) xs

sub :: [Int] -> [Int] -> [Int]
sub [] [] = []
sub [_] [] = []
sub [] [_] = []
sub (x:xs) (y:ys) = abs (x - y) : (sub xs ys)
