#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++) {
    if (N <= 3) {
      if ((s[i] == 1) && (c[i] == 0)) {
        cout << -1 << endl;
        return 0;
      }
    }
    if (N <= 2) {
      if ((s[i] == 2) && (c[i] == 0)) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  bool set[5] = {false};
  int num[5] = {0};
  for (int i = 0; i < M; i++) {
    int t = s[i];
    int n = c[i];
    if (false == set[t]) {
      num[t] = n;
      set[t] = true;
    } else {
      if (num[t] != n) {
        cout << -1 << endl;
        return 1;
      }
    }
  }
  int result = num[1] * 100 + num[2] * 10 + num[3];
  cout << result << endl;
  return 0;
}
