#include <bits/stdc++.h>
using namespace std;
using LL = long long;
bool flag=false; 
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
signed main()
{
  string ans="";
    LL n,m;
    cin >> n>>m;
      vector<pair<int,bool>> a(m); 
  REP(i,m)a[i]=make_pair(10000,false);
    REP(i,m){
      int t,s;
      cin >> t >>s;
    if(a[t].second==false||a[t].first==s){
      a[t].first=s;
      a[t].second=true;
    }else{
      cout << -1;
    return 0;
     }
    } 
if(a[i].first==0&&n=0){
  cout << 0;
  return 0;
}
  vector
  for(int i = 1; i<=n;i++){
    if(a[i].first!=0)flag=true;
      if(flag){
        if(a[i].first==10000)a[i].first=0;
        ans+=to_string(a[i].first);
      }
    }
   ans[0]=1;
  cout << ans;
  }