#include <bits/stdc++.h>
using namespace std;

int main(){
  int N;
  int M;
  cin << N;
  cin << M;
  int S;
  int i;
  vector<int> vec(3);
  
  for(i=0;i<3;i++){
   vec.at(i)=-1; 
  }
  for(i=0;i<M;i++){
  cin << S;
  cin << M;
  if(vec.at(S-1)!=-1 && vec.at(S-1)!=M){
 out=-1; 
      i=M;
  }else{
   vec.at(S-1)=M; 
  }
  }
  
  if (N==3){
    if(vec.at(0)==0 || vec.at(1)==0) {
   out=-1;
    }else{
     cout << vec.at(0)*100+vec.at(1)*10+vec.at(2) <<endl; 
    }
  }else if(N==2){
    if(vec.at(0)==0){
     out=-1; 
    }else{
      cout << vec.at(0)*10+vec.at(1) <<endl;
    }
  }else if(out!=-1){
    cout << vec.at(0) <<endl;
  }
 

}