#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);
  }
  int max = 1;
  for (long long i = 0; i < (long long)(N); i++) {
    max *= 10;
  }
  int judge = 0;
  for (long long i = 0; i < (long long)(max + 1); i++) {
    string a = to_string(i);
    for (long long j = 0; j < (long long)(M); j++) {
      if (s.at(j) == 1 && c.at(j) == 0 && a.size() != 1) {
        cout << -1 << endl;
        return 0;
      }
      if (a.size() < s.at(j)) {
        judge = 1;
      } else if (ctoi(a.at(s.at(j) - 1)) != c.at(j)) {
        judge = 1;
      }
    }
    if (judge == 0) {
      cout << i << endl;
      return 0;
    }
    judge = 0;
  }
  cout << -1 << endl;
}
