#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
#define endl '\n'
using ll = long long;
#define int ll
using db = long double;
using ii = pair<int, int>;

const int N = 1e5 + 5, LG = 19, MOD = 998244353;
const int SQ =320;
const long double EPS = 1e-7;
set<int>st[10];
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
  int n,m;
  cin>>n>>m;
  for(int i = 0, s, c;i<m;i++){
      cin>>s>>c;
    st[s].insert(c);
  }
  f(i,1,n+1)if(st[i].size()>1){
    cout<<-1<<'\n';
    return 0;
  }
  if(st[1].count(0)){
    cout<<-1<<'\n'
    return 0;
  }

  f(i,1,n+1){
    if(st[i].empty())
      cout<<0+(i==1);
    else
      cout<<*st[i].begin();
  }

  return 0;
}
