#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s, c;
  for (int i = 0; i < (int)(m); i++) {
    int si, ci;
    cin >> si >> ci;
    s.push_back(si);
    c.push_back(ci);
  }
  for (int i = 1; i < 1000; i++) {
    int temp = i, k = 0;
    vector<int> num;
    while (temp) {
      k++;
      num.insert(num.begin(), temp % 10);
      temp /= 10;
    }
    if (k != n) continue;
    bool b = true;
    for (int j = 0; j < (int)(m); j++) {
      if (num[s[j] - 1] != c[j]) {
        b = false;
        break;
      }
    }
    if (b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
