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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  rep(i,m) cin >> s.at(i) >> c.at(i);
  
  int st = 0;
  if (n >= 2) st = pow(10,n-1);
  int ed = pow(10,n);
  int ans = -1;
  for (int i = st; i < ed; i++) {
    string x = to_string(i);
    bool t = true;
    rep(j,m) {
      if (x.at(s.at(j)-1) != c.at(j)) t = false;
    }
    if (t) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}