#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  int s[10] = {0};
  int c[10] = {0};
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  for (int i = 0; i < M; i++) {
    int target1 = s[i];
    int data1 = c[i];
    if ((target1 == 1) && (data1 == 0)) {
      cout << -1 << endl;
      return 0;
    }
    if (N != 3) {
      if ((target1 == 2) && (data1 == 0)) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  bool set[5] = {false};
  int num[5] = {0};
  for (int i = 0; i < M; i++) {
    int target = s[i];
    int data = c[i];
    if (false == set[target]) {
      num[target] = data;
      set[target] = true;
    } else {
      if (num[target] != data) {
        cout << -1 << endl;
        return 1;
      }
    }
  }
  int result = num[1] * 100 + num[2] * 10 + num[3];
  cout << result << endl;
  return 0;
}
