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

int main(){
  int n, m;
  cin >> n >> m;
  vector<P> num(n);
  num[n-1].first = 1;
  rep(i,n-1) num[i].first = 0;
  rep(i,n) num[i].second = 0;
  int out=0;
  int s, c;
  rep(i,m) {
    cin >> s >> c;
    if ((s==1) && (c==0)) {out = 1; break;}
    if (num[n-s].second==0) {num[n-s].first = c; num[n-s].second = 1;}
#    else if ((num[n-s].second==1) && (num[n-s].first==c)){continue;}
    else {out=1;break;}
  }
  if (out==1) cout << -1 << endl;
  else {
    int ans = num[n-1].first;
    for (int j=n-2;j>=0;--j) ans = 10*ans + num[j].first;
    cout << ans << endl;
  }
}