#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long INF = 1e18;
const double pi = acos(-1);
int main(void) {
  long long n, m;
  cin >> n >> m;
  set<long long> a, b, c;
  for (int i = 0; i < (m); ++i) {
    long long s, t;
    cin >> s >> t;
    s--;
    if (s == 0)
      a.insert(t);
    else if (s == 1)
      b.insert(t);
    else
      c.insert(t);
  }
  bool ok = true;
  if (a.size() >= 2 || b.size() >= 2 || c.size() >= 2) ok = false;
  if (*a.begin() == 0) ok = false;
  if (!ok)
    cout << -1 << endl;
  else {
    for (int i = 0; i < (n); ++i) {
      if (i == 0)
        cout << *a.begin();
      else if (i == 1)
        cout << *b.begin();
      else
        cout << *c.begin();
    };
    cout << endl;
  }
  return 0;
}
