#include <bits/stdc++.h>
using namespace std;
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (long long i = 0; i < (long long)(M); i++) {
    cin >> s.at(i) >> c.at(i);
  }
  for (long long i = 0; i < (long long)(1000); i++) {
    int nx;
    int keta = 0;
    string d = to_string(i);
    if (d.size() != N) continue;
    bool ok = true;
    for (long long j = 0; j < (long long)(M); j++) {
      if (d.at(s.at(i) - 1) != c.at(i)) ok = false;
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
