#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int ten[4] = {0, 1, 10, 100};
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  int min, max;
  if (n == 1) {
    min = 0;
    max = 10;
  }
  if (n == 2) {
    min = 10;
    max = 100;
  }
  if (n == 3) {
    min = 100;
    max = 1000;
  }
  bool ok;
  for (int i = min; i < max; i++) {
    ok = true;
    for (int j = 0; j < m; j++) {
      if (s[j] == 1) {
        if (i % 10 != c[j]) ok = false;
      }
      if (s[j] == 2) {
        if ((i / 10) % 10 != c[j]) ok = false;
      }
      if (s[j] == 3) {
        if ((i / 100) % 10 != c[j]) ok = false;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
