#include <bits/stdc++.h>
using namespace std;
int power(int n) {
  int res = 1;
  for (int i = 0; i < (n); ++i) res *= 10;
  return res;
}
bool check(int n, int s, int c) {
  vector<int> v(3);
  for (int i = 0; i < (3); ++i) {
    v[2 - i] = n % 10;
    n /= 10;
  }
  if (v[s - 1] == c)
    return true;
  else
    return false;
}
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];
  for (int i = power(n - 1); i < power(n); i++) {
    bool ok = true;
    for (int j = 0; j < (m); ++j) {
      if (!check(i, s[j], c[j])) ok = false;
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
