#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
ll n,m,s,c,x,y,z,countx,county,countz;

x=-1;
y=-1;
z=-1;
countx=0;
county=0;
countz=0; 

cin >> n >> m;

for(ll i=0 ; i<m ; i++){

  cin >> s >> c;
    
  if(s==1){
     countx+=1;
    if(countx==1){
      x=x+1;
      x+=c; 
      }else{
        if(c!=x){
          cout << "-1" << endl;
          return 0;
        }
      }
  }
  
  if(s==2){
     county+=1;
    if(county==1){
      y=y+1;
      y+=c; 
      }else{
        if(c!=y){
          cout << "-1" << endl;
          return 0;
        }
      }
  }
    
  if(s==3){
     countz+=1;
    if(countz==1){
      z=z+1;
      z+=c; 
      }else{
        if(c!=z){
          cout << "-1" << endl;
          return 0;
        }
      }
  }
}



if(n==1){
  if(x==-1){
    x=0;
    cout << x << endl;
    return 0;
  }else{
  cout << x << endl;
  return 0;
  }
 }

if(n==2 && ((x*10+y)!=0) && x!=0 ){
  if(x==-1){
    x=1;
    if(y==-1){
      y=0;
    }
    cout << x*10+y << endl;
    return 0;
  }else{
    if(y==-1){
      y=0
    }
  cout << x*10+y << endl;
  return 0;
  }
}
  

if(n==3 && ((x*100+y*10+z)!=0) && x!=0){
  if(x==-1){
    x=1;
    if(y==-1){
      y=0;
    }
     if(z==-1){
      z=0;
    }
    cout << x*100+y*10+z <<endl;
    return 0;
    }else{
      if(y==-1){
      y=0;
    }
     if(z==-1){
      z=0;
    }
  cout << x*100+y*10+z <<endl;
  return 0;
  } 
}

cout << "-1" << endl;

}




