#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m; cin>>n>>m;
  map<int,int> memo;
  map<int,bool> judge;
  bool ansjudge=1;
  rep(i,m){
    int s,c; cin>>s>>c;
    if(judge[s]&&memo[s]!=c) ansjudge=0;
    else {memo[s]=c;
          judge[s]=1;
         }
  }
  if(!ansjudge) cout<<-1<<endl;
  else if(n==1) cout<<memo[1]<<endl;
  else if(memo[1]==0&&judge) cout<<-1<<endl;
  else if(memo[1]==0){
    cout<<1;
    rep(i,n-1) cout<<memo[i+2];
  }else rep(i,n) cout<<memo[i+1];
}
