#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>> a;
  rep(i,m) {
    cin >> a[i].first >> a[i].second;
  }
  
  rep(x,1000) {
    int keta = 1;
    vector<int> d(1,x%10);
    int xx = x/10;
    while(xx) {
      keta++;
      d.push_back(xx%10);
      xx /= 10;
    }
    reverse(d.begin(),d.end());
    
    if(keta == n) {
      bool ok = true;
      rep(i,m) if(d[a[i].first-1] != a[i].second) ok = false;   
    }
    if(ok) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

