#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[1], a2[2];
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];
  b[0] = a0[0];
  b[1] = a1[0];
  b[2] = a2[0];
  if (b[0] == 0)
    cout << -1;
  else {
    for (long long i = 0; i < n; i++) {
      cout << b[i];
    }
  }
}
