#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  long long int i, j, k, l, N, M, a, b, c;
  cin >> N >> M;
  map<long long int, long long int> nn, kk;
  long long int arrp[10] = {0};
  bool tra[10] = {false};
  bool flr = false;
  for (i = 0; i < M; i++) {
    cin >> a >> b;
    if (!(b == 0 && a == 1)) {
      if (tra[a] == true) {
        if (arrp[a] != b) {
          flr = true;
        }
      } else {
        arrp[a] = b;
        tra[a] = true;
      }
    } else {
      if (b == 0 && N == 1) {
        arrp[a] = 0;
        tra[a] = true;
      }
      if (tra[a] == true) {
        if (arrp[a] != b) {
          flr = true;
        }
      }
    }
  }
  if ((arrp[1] == 0 && N != 1) || (flr == true)) {
    cout << -1 << endl;
  } else {
    for (i = 1; i <= N; i++) {
      cout << arrp[i];
    }
    cout << endl;
  }
  return 0;
}
