#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int x, y, c;
  cin >> x >> y;
  c = y;
  int nb[x];
  for (int i = 0; i < x; i++) {
    nb[i] = -1;
  }
  int a, b;
  bool guess = true;
  while (c-- && guess) {
    cin >> a >> b;
    if (nb[a - 1] != -1 && nb[a - 1] != b) {
      guess = false;
    }
    if ((b == 0 && a == 1) && x > 1) {
      guess = false;
    }
    nb[a - 1] = b;
  }
  if (guess) {
    if (nb[0] == -1) {
      nb[0] = 1;
    }
    for (int i = 0; i < x; i++) {
      if (nb[i] != -1) {
        cout << nb[i];
      } else {
        cout << 0;
      }
    }
  } else {
    cout << -1;
  }
  return 0;
}
