#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAX = 510000;
const int INF = 1e9;
const double pi = acos(-1);
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> b(m);
  vector<int> c(m);
  for (long long i = 0; i < (m); i++) cin >> b[i] >> c[i];
  for (int i = pow(10, n - 1); i < pow(10, n); i++) {
    string s = to_string(i);
    bool ok = true;
    for (long long j = 0; j < (m); j++) {
      if ((s[b[j] - 1] - '0') != c[j]) ok = false;
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  if (n == 1) {
    bool can = true;
    for (long long i = 0; i < (m); i++) {
      if (b[i] != 1 || c[i] != 0) {
        can = false;
      }
    }
    if (can) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
