#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i] = n - s[i];
  }
  for (int i = 0; i < 1000; i++) {
    if (pow(10, n) > i && pow(10, n - 1) <= i) {
      bool ok = 1;
      for (int j = 0; j < m; j++) {
        if (i / (int)pow(10, s[j]) % (int)pow(10, s[j] + 1) != c[j]) ok = 0;
      }
      if (ok) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
}
