#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, f = 1;
  scanf("%d %d", &n, &m);
  vector<int> d(n, -1);
  for (int i = 0; i < m; i++) {
    int s, c;
    scanf("%d %d", &s, &c);
    if (s > n || (n > 1 && !i && !c))
      f = 0;
    else {
      if (d[s - 1] == -1)
        d[s - 1] = c;
      else if (d[s - 1] != c)
        f = 0;
    }
  }
  if (f) {
    for (auto &x : d)
      if (x == -1) x = 0;
    int o = d[0];
    for (int i = 1; i < n; i++) {
      o *= 10;
      o += d[i];
    }
    printf("%d\n", o);
  } else
    printf("-1\n");
}
