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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> c(m);
  rep(i,m) cin >> c[i].first() >> c[i].second();
  
  rep(x,1000) {
    int keta = 1;
    vector<int> d(0);
    while(x / 10) {
      keta++;
      d.push_back(x % 10);
      x /= 10;
    }
    reverse(d.begin(),d.end());
    
    if(keta != n) continue;
    bool ok = true;
    rep(i,m) {
      if(d[c[i].first - 1] == c[i].second) continue;
      ok = false;
    }
    if(ok) {
      cout << x << endl;
      return 0;
    }
    
    cout << -1 << endl;
    
  }
  
  
}

