#include<bits/stdc++.h>

using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int n,m;cin>>n>>m;
  int s,c;
  vector<int> a(n,-1);
  rep(i,m){
    cin>>s>>c;
    if(!(n>=2 && s==1 && c==0)&&(a[s-1]==-1 ||a[s-1]==c)){
      a[s-1]=c;
    }else{
      cout<<-1<<endl;
      return 0;
    }
  }
  rep(i,n) n>=2 && i==0 && a[i]==-1 ? cout<<1 : a[i]!=-1 ? cout<<a[i] : cout<<0;
  cout<<endl;
}