#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (m); ++i) cin >> s[i] >> c[i];
  int ans = -1;
  for (int i = pow(10, (n - 1)); i < pow(10, n); ++i) {
    bool ok = true;
    vector<int> x(n);
    int y = i;
    for (int j = 0; j < (n); ++j) {
      x[j] = y % 10;
      y /= 10;
    }
    for (int j = 0; j < (m); ++j) {
      if (x[n - s[j]] != c[j]) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
