#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, i, a, b, count;
  count = 1;
  cin >> N >> M;
  int number[N];
  for (i = 0; i < N; i++) {
    number[i] = -1;
  }
  for (i = 0; i < M; i++) {
    a = 0;
    b = 0;
    cin >> a >> b;
    if ((number[a - 1] != -1) && (number[a - 1] != b)) {
      count = 0;
    }
    number[a - 1] = b;
  }
  if ((number[0] == -1) && (N != 1)) {
    number[0] = 1;
  }
  for (i = 0; i < N; i++) {
    if (number[i] == -1) number[i] = 0;
  }
  if ((count == 1) && (number[0] != 0)) {
    for (i = 0; i < N; i++) cout << number[i];
  }
  if (count == 0) {
    cout << "-1";
  }
  if (number[0] == 0) {
    cout << "-1";
  }
  return 0;
}
