#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-6;
const int INF = 0x3f3f3f3f;
void solve() {
  int n, m, a[10][2];
  cin >> n >> m;
  for (int i = 0; i < m; ++i) cin >> a[i][0] >> a[i][1];
  set<int> s;
  for (int i = 1; i <= n; ++i) {
    s.clear();
    for (int j = 0; j < m; ++j) {
      if (a[j][0] == i) s.insert(a[j][1]);
    }
    if (s.size() > 1) {
      cout << -1 << endl;
      return;
    } else if (s.size() == 0) {
      cout << 0;
    } else {
      cout << *s.begin();
    }
  }
  cout << endl;
}
int main() {
  solve();
  return 0;
}
