using System;

class GuessMinNumber{
  static void Main(){
      
      var input = Console.ReadLine().Split(' ');
      var k = int.Parse(input[0]);
      int[] guess = new int[k];
      int sum = 0;
      int ans = -1;
      
      for(var i = 0; i < k ;i++){
          guess[i] = -1;
      }
      
      for(var i = 0; i < int.Parse(input[1]);i++){
          var number = Console.ReadLine().Split(' ');
          if(guess[int.Parse(number[0]) -1] == -1 || guess[int.Parse(number[0]) -1] == int.Parse(number[1])){
            guess[int.Parse(number[0]) -1] = int.Parse(number[1]) ;
          }else if(guess[int.Parse(number[0]) -1] != -1){
             // ans = -1;
              Console.WriteLine(ans);
              return;
          }else{
              Console.WriteLine(ans);
              return;
          }
      }
      
      for(var i = 0;i< guess.Length;i++){
          if(guess[i] == -1){
              if(i == 0){
                  guess[i] = 1;
              }else{
                  guess[i] = 0;
              }
          }
      }
      
         if(guess[0] != 0){
             for(var i = guess.Length; i > 0 ;i--){
                 sum  += guess[ guess.Length - i] * (int)Math.Pow(10,i-1); 
             }
             ans = sum;
         }else if(guess[0] == 0 && guess.Length == 1){
             ans = 0;
         }
      
      
      Console.WriteLine(ans);
  }
}
 