#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int ket = 0;
  for (int i = 0; i < 1000; i++) {
    vector<int> ke(n);
    int t = i;
    int ket = 0;
    for (int i = 0; i < n; i++) {
      if (t) {
        ke[ket] = t % 10;
        t /= 10;
        ket++;
      }
    }
    if (ket != n) continue;
    reverse(ke.begin(), ke.end());
    bool ok = true;
    for (int j = 0; j < m; j++) {
      if (ke[s[j] - 1] != c[j]) ok = false;
    }
    if (ok) {
      cout << i;
      return 0;
    }
  }
  cout << "-1";
}
