#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n, i, v;
  cin >> n >> m;
  int a[m], b[m];
  int c[n + 1];
  for (i = 1; i <= n; i++) c[i] = -1;
  for (i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
    if (c[a[i]] == -1) {
      c[a[i]] = b[i];
    } else {
      v = 1;
    }
  }
  if (v == 1 || c[1] == 0 || c[n] == 0)
    cout << "-1\n";
  else {
    for (i = 1; i <= n; i++) {
      if (c[i] == -1) {
        cout << 3;
      } else
        cout << c[i];
    }
  }
  cout << endl;
}
