import Control.Monad
import Control.Applicative
import Data.Monoid
import Data.Maybe
import Data.List

data Dat = Num Int | X deriving (Show, Eq)
data Lattice a = Value a | Top | Bot deriving (Eq, Show)
type FinRange a = (Lattice a, Lattice a)
newtype Range a = Range { getRange :: Maybe (FinRange a) } deriving (Eq, Show)

instance Ord a => Ord (Lattice a) where
    compare (Value x) (Value y) = compare x y
    compare Bot Bot = EQ
    compare Top Top = EQ
    compare Bot _ = LT
    compare _ Top = LT
    compare _ _   = GT

between :: Ord a => a -> a -> Range a
between x y = if x < y then Range $ Just (Value x, Value y) else Range Nothing
lesthan x   = Range $ Just (Bot, Value x)
grtthan x   = Range $ Just (Value x, Top)
none        = Range Nothing
total       = Range $ Just (Bot, Top)

appendRange :: Ord a => FinRange a -> FinRange a -> Range a
appendRange (x, y) (x', y')
    | y < x' || y' < x  = none
    | otherwise         = Range $ Just (max x x', min y y')

instance Ord a => Monoid (Range a) where
    mempty = total
    mappend (Range (Just a)) (Range (Just b)) = appendRange a b
    mappend _ _ = none

makePair :: [Dat] -> [(Dat, Dat)]
makePair [] = []
makePair (x:xs) = snd $ foldl (\ (a, l) b -> (b, l ++ [(a,b)])) (x, []) xs

imap :: (Int -> a -> b) -> [a] -> [b]
imap f = zipWith f (from 0)
    where from n = n:(from (n + 1))

hoge :: Dat -> Dat -> Range Int
hoge (Num n) (Num m) = if n < m then total else none
hoge X (Num n) = lesthan n
hoge (Num n) X = grtthan n
hoge X X = none

solve :: [Dat] -> String
solve xs = case mconcat . imap f . makePair $ xs of
    Range Nothing -> "none"
    Range (Just (Value x, Value y))
        | y - x < 2  -> "none"
        | y - x == 2 -> show (x + 1)
        | otherwise  -> "ambiguous"
    _ -> "ambiguous"
    where f i (x,y) = if even i then hoge x y else hoge y x

fromString :: String -> Dat
fromString "x" = X
fromString n   = Num . read $ n

main :: IO ()
main = do
    n <- read <$> getLine :: IO Int
    when (n /= 0) $ do
      dats <- fmap fromString . words <$> getLine :: IO [Dat]
      putStrLn . solve $ dats
      main