#include <bits/stdc++.h>
using namespace std;
long long ans, mx, sum, mn = 1e8, cnt;
long long idx0, idx1, idx2;
long long a0[5], a1[5], a2[5];
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    if (a == 0)
      a0[idx0++] = b;
    else if (a == 1)
      a1[idx1++] = b;
    else if (a == 2)
      a2[idx2++] = b;
  }
  sort(a0, a0 + idx0);
  sort(a1, a1 + idx1);
  sort(a2, a2 + idx2);
  long long b[3];
  for (long long i = 0; i < idx0; i++) {
    if (a0[i] >= 0) {
      b[0] = a0[i];
      break;
    }
  }
  for (long long i = 0; i < idx1; i++) {
    if (a1[i] >= 0) {
      b[1] = a1[i];
      break;
    }
  }
  for (long long i = 0; i < idx2; i++) {
    if (a2[i] >= 0) {
      b[2] = a2[i];
      break;
    }
  }
  if (b[0] == 0 && n != 1)
    cout << -1;
  else {
    for (long long i = 0; i < n; i++) {
      if (b[i] < 0) {
        cout << -1;
        return 0;
      }
      cout << b[i];
    }
  }
}
