#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
    s.at(i)--;
  }
  bool ok;
  for (int i = 0; i < 1000; i++) {
    ok = true;
    string S = to_string(i);
    if (S.size() != n) continue;
    for (int j = 0; j < m; j++) {
      if (S.at(s.at(j)) != (char)(c.at(j) + '0')) ok = false;
    }
    if (ok) {
      cout << S << endl;
      break;
    }
  }
  if (!ok) cout << -1 << endl;
}
