#include <bits/stdc++.h>
template <class T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void) {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int(i) = 0; (i) < (m); (i)++) cin >> s[i] >> c[i];
  for (int i = 0; i < 1000; i++) {
    if (to_string(i).size() != n) continue;
    bool ok = true;
    for (int(j) = 0; (j) < (m); (j)++) {
      if (s[j] == 1) {
        if (i / 100 != c[j]) ok = false;
      } else if (s[j] == 2) {
        if (i / 10 % 10 != c[j]) ok = false;
      } else {
        if (i % 10 != c[j]) ok = false;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
