solve :: [Int] -> Int -> Int -> Int
solve [] _ res = res
solve (x:xs) cnt res = solve xs (cnt + 1) res'
  where res' = if x == cnt
               then res
               else res + 1

main :: IO ()
main = do
  getLine
  input <- map read . words <$> getLine
  putStrLn $ if solve input 1 0 <= 2 then "YES" else "NO"