#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpii = vector<pii>;
int main(void) {
  int n, m;
  while (scanf("%d%d", &n, &m) == 2) {
    vi x(n + 1, -1);
    vi s(m), c(m);
    for (int i = 0; i < m; i++) scanf("%d%d", &s[i], &c[i]);
    bool is_ok = true;
    for (int i = 0; i < m; i++) {
      if (x[s[i]] >= 0 && x[s[i]] != c[i]) is_ok = false;
      x[s[i]] = c[i];
    }
    if (n != 1 && x[1] == 0) is_ok = false;
    for (int i = 1; i <= n; i++) {
      if (x[i] < 0) x[i] = (i == 1);
    }
    if (is_ok) {
      for (int i = 1; i <= n; i++) printf("%d", x[i]);
      printf("\n");
    } else {
      printf("%d\n", -1);
    }
  }
  return 0;
}
