#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int k = 0; k < m; k++) {
    cin >> s[k] >> c[k];
  }
  int ulim = pow(10, n);
  int llim = pow(10, n - 1);
  if (n == 1) llim = 0;
  int dig[n];
  int k = llim;
  int kc;
  bool jud;
  while (k < ulim) {
    kc = k;
    for (int j = 0; j < n; j++) {
      dig[j] = kc % 10;
      kc /= 10;
    }
    jud = true;
    for (int j = 0; j < m; j++) {
      if (dig[3 - s[j]] != c[j]) jud = false;
    }
    if (jud) break;
    k++;
  }
  if (k == ulim)
    cout << "-1\n";
  else
    cout << k << "\n";
}
