#include<iostream>
using namespace std;
int main(){
  int N,M; // M<=5,N<=3
  int sc[5][2]; // sc * M *2
  int ans[3]{-1,-1,-1}; // N<=3
  bool error{false};
  int ans_num{0};
  bool debug{true};
  
  cin >>N >> M;
  if(debug)cout << "N=" << N << "," << "M=" << M << endl;
    
  for (int i=0;i<M;i++){
    cin >> sc[i][0] >> sc[i][1];
    if(debug)cout << "s=" << sc[i][0] << "," << "c=" << sc[i][1] << endl; 
    
    if((ans[sc[i][0]-1]!=-1)and(ans[sc[i][0]-1]!=sc[i][1])){
        error=true;
        if(debug)cout<<"error1"<<endl;
    }else if(sc[i][1]<0){
        error=true;
        if(debug)cout<<"error2"<<endl;    

    }else if(sc[i][1]>9){
        error=true;
        if(debug)cout<<"error3"<<endl;    

    }else{
    ans[sc[i][0]-1]=sc[i][1];    
      
    }
  }
  
  for(int i=0;i<N;i++){
    if(ans[i]==-1){
      ans[i]=0;
    }
  }
  
  if(debug)cout << ans[0] <<ans[1] << ans[2] <<endl;
  
  if(error){
  	cout << -1;
  }else if((N==1)and(ans[0]==0))
    cout << -1;
  else if((N==2)and(ans[1]==0))
    cout << -1;
  else if((N==3)and(ans[2]==0))
    cout << -1;
  else{
    switch(N){
      case 1:
        ans_num= ans[2];
      case 2:
        ans_num= 10*ans[1]+1*ans[2];
      case 3:
       	ans_num= 100*ans[0]+10*ans[1]+1*ans[2];
      default:
        ans_num=-1
    }
    cout << ans_num;
  }
  
  return 0;

}
