#include <bits/stdc++.h>
using namespace std;
using namespace std;
int jousu(int, int);
int jousu(int x00, int y00) {
  int z00 = 1;
  for (int i = 0; i < y00; i++) {
    z00 *= x00;
  }
  return z00;
}
int kurai(int x00, int y00) {
  int z00 = (x00 % jousu(10, y00)) / jousu(10, y00 - 1);
  return z00;
}
int keta(int x00) {
  int z00 = x00;
  int w00 = 0;
  while (z00 != 0) {
    z00 /= 10;
    w00++;
  }
  return w00;
}
int main() {
  int n, m, s = 999;
  cin >> n >> m;
  vector<pair<int, int>> vec(m);
  vector<int> vec2(3, -1);
  for (int i = 0; i < m; i++) {
    cin >> vec[i].first >> vec[i].second;
  }
  if (n == 1) {
    s = 0;
  } else if (n == 2) {
    s = 10;
  } else if (n == 3) {
    s = 100;
  }
  for (int i = 0; i < m; i++) {
    if (vec2[vec[i].first - 1] >= 0 &&
        vec2[vec[i].first - 1] != vec[i].second) {
      printf("-1");
      return 0;
    }
    if (vec[i].first == 3) {
      s = (s / 10 * 10) + vec[i].second;
    } else if (vec[i].first == 2) {
      s = (s / 100 * 100) + (s % 10) + (vec[i].second * 10);
    } else if (vec[i].first == 1) {
      s = (s % 100) + (vec[i].second * 100);
    }
    vec2[vec[i].first - 1] = vec[i].second;
  }
  if (s / 100 == 0) {
    printf("-1");
    return 0;
  }
  printf("%d", s);
}
