#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
bool test(int i, vector<P> p) {
  bool result = true;
  string s = to_string(i);
  for (int j = 0; j < (p.size()); ++j) {
    P pp = p[j];
    if ((s[pp.first - 1] - '0') != pp.second) {
      result = false;
      break;
    }
  }
  return result;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> sc(n);
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    sc[i] = make_pair(s, c);
  }
  int result = -1;
  if (n == 1) {
    for (int i = 0; i <= 9; i++) {
      if (test(i, sc)) {
        result = i;
        break;
      }
    }
  } else if (n == 2) {
    for (int i = 10; i <= 99; i++) {
      if (test(i, sc)) {
        result = i;
        break;
      }
    }
  } else if (n == 3) {
    for (int i = 100; i <= 999; i++) {
      if (test(i, sc)) {
        result = i;
        break;
      }
    }
  }
  cout << result << endl;
  return 0;
}
