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