data SegTree = Empty { contents :: (Int,Int)
                      ,maxcont :: (Int,Int)}| 
               Node { contents :: (Int,Int)
                     ,maxcont :: (Int,Int)
                     ,leftTree :: SegTree
                     ,rightTree :: SegTree}

empty :: SegTree
empty = Empty (-1,-1) (-1,-1)

comp :: (Int,Int) -> (Int,Int) -> (Int,Int)
comp (a,b) (x,y)
  | b == y = ((min a x),b)
  | b < y  = (x,y)
  | b > y  = (a,b)

insert :: (Int,Int) -> SegTree -> SegTree
insert (x,y) (Empty _ _) = (Node (x,y) (x,y) empty empty)
insert (x,y) (Node (a,b) (c,d) left right)
  | x == a = Node (a,b+y) (c,d) left right
  | x < a  = Node (a,b) (c,d) (insert (x,y) left) right
  | x > a  = Node (a,b) (c,d) left (insert (x,y) right)

update :: Int -> SegTree -> SegTree
update _ (Empty _ _) = empty
update x (Node (a,b) (c,d) left right)
  | x == a = (Node
                (a,b)
                ((a,b) `comp` (maxcont left) `comp` (maxcont right))
                left
                right)
  | x < a  = (Node
                (a,b)
                ((a,b) `comp` (maxcont (update x left)))
                (update x left)
                right)
  | x > a  = (Node
                (a,b)
                ((a,b) `comp` (maxcont (update x right)))
                left
                (update x right))

format :: (Int,Int) -> String
format (a,b) = (show a) ++ " " ++ (show b)

main :: IO ()
main = do
  nq <- getLine
  let [n,q] = map (read :: String -> Int) $ words nq
      counter = q
      initTree = empty
  loopq counter initTree

loopq counter tree = do
  if counter <= 0
    then return ()
    else do
      av <- getLine
      let [a,v] = map (read :: String -> Int) $ words av
          tree' = update a $ insert (a,v) tree
          ans = maxcont tree'
      putStrLn $ format ans
      loopq (counter - 1) tree'