#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<(int)c;i++)
#define print(var) cout<<var<<endl;
#define DEBUG(var) cerr<<var<<endl

const int inf = 1000000000;//10^9


int main(){
  int N,M;
  cin>>N>>M;

  vector<vector<int> > data(M,vector<int>(2));


  rep(i,M) cin>>data[i][0]>>data[i][1];



  map<int,int> mp;
  rep(i,M){
    if(data[i][0]>N){
      print("-1");
      return 0;
    }

    if(!mp.count(data[i][0])){
      mp[data[i][0]]=data[i][1];
    }else if(mp[data[i][0]]==data[i][1]){
      continue;
    }else{
      print("-1");
      return 0;
    }
  }

  int ans=0;
  bool good=false;
  for(int i=N;i>0;i--){

    if(i==N&&!mp.count(i)&&N!=1){
    ans+= (int)pow(10,i);
  }
    if(mp.count(i)){
      if(mp[i]==0&&(!good)){
      print("-1");
      return 0;
    }
      ans+=(int)pow(10,N-i)*mp[i];
      if(mp[i]!==0){
        good=true;
      }
    }
  }
  print(ans);


  return 0;
}