#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int d[4];
  for (int i = 0; i < 4; i++) {
    d[i] = -1;
  }
  for (int m = 0; m < M; m++) {
    int s, c;
    cin >> s >> c;
    if (d[s - 1] != -1 && d[s - 1] != c) {
      cout << "-1";
      return 0;
    } else {
      d[s - 1] = c;
    }
  }
  if (d[0] == 0) {
    if (N == 1) {
      cout << 0;
    } else {
      cout << "-1";
      return 0;
    }
  } else if (d[0] == -1) {
    cout << 1;
  } else {
    cout << d[0];
  }
  for (int n = 1; n < N; n++) {
    if (d[n] != -1) {
      cout << d[n];
    } else {
      cout << 0;
    }
  }
  return 0;
}
