#include <bits/stdc++.h>
using namespace std;

signed main(){
  int n,m;cin>>n>>m;
  vector<int> v(n,-1);
  v[0]=1;
  while(m--){
    int s,c;cin>>s>>c;
    if(~v[s-1]&&v[s-1]!=c)fin(-1);
    v[s-1]=c;
  }
  for(int i=0;i<n;i++){
    cout<<(~v[i]?v[i]:0);
  }
  cout<<endl;
}
