import Data.Maybe
import Data.List
import Control.Monad
import qualified Data.ByteString.Char8 as BS


ave :: [Double] -> Maybe Double
ave [] = Nothing
ave x = Just $ (sum x) / (fromIntegral $ length x)

f :: [Int] -> [[Int]] -> Maybe [(Int,Double)]
f [] a = Just [(0,-1)]
f (x:xs) a = do 
    ys <- f xs a
    z <- ave $ map (\z -> snd $ fromJust $ find (\(n,e) -> n == (last z)) ys) $ filter (\z -> (head z) == x) a
    return $ (x,z+1):ys
    -- return $ (x,((ave $ map (\z -> snd $ fromJust $ find (\(n,e) -> n == (last z)) ys) $ filter (\z -> (head z) == x) a) + 1):ys)

g :: [a] -> [[a]]
g (x:xs) = xs:(map (\y -> x:y) (g xs))
g [] = [] 

main :: IO ()
main = do
    [n,m] <- (map (fst . fromJust . BS.readInt)) . BS.words <$> BS.getLine
    a <- replicateM m ((map (fst . fromJust . BS.readInt)) . BS.words <$> BS.getLine)
    let b = map (\x -> [n,0]:x) (a:(g a))
    putStrLn $ show $ minimum (map (snd . head) $ catMaybes $ map (f [1..n]) b)
