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

int main(){
  int n,m;
  cin >> n >> m;
  vector<P> p(m);
  rep(i,m) cin >> p.at(i).first >> p.at(i).second;
  rep(x,1000){
    if(x.size() != n) continue;
    int nx = x;       
    vector<int> d(1);
    while(nx){
      d.push_back(nx%10);
      nx /= 10;
    }
    reverse(d.begin(),d.end()); //数字を、桁ごとにアクセス可能な形にした。
    
    bool ok = true;
    rep(i,m){
      if(d.at(p.at(i).first-1) != p.at(i).second) ok = false;
    }
    if( ok ){
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
