#include <bits/stdc++.h>
using namespace std;
long long ans, mx, sum, mn = 1e8;
long long cnt;
long long c[3];
long long d[3];
int main() {
  long long n, m;
  cin >> n >> m;
  c[0] = 9;
  c[1] = 9;
  c[2] = 9;
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    d[a]++;
    if (a == n - 1 && c[a] > b && b > 0) {
      c[a] = b;
    } else if (a == 0 && c[a] > b && b > 0) {
      c[a] = b;
    } else if (c[a] > b) {
      c[a] = b;
    }
  }
  for (long long i = 0; i < n; i++) {
    if (d[i] == 0) c[i] = 0;
  }
  if (c[0] == 0)
    cout << -1;
  else {
    for (int i = 0; i < n; i++) {
      cout << c[i];
    }
  }
}
