#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(n);
  for (int i = 0; i < (m); i++) {
    cin >> p[i].first >> p[i].second;
    p[i].first--;
  }
  bool ok = true;
  for (int i = 0; i < (m); i++) {
    for (int j = i; i < m; i++) {
      if (p[i].first != p[j].first) continue;
      if (p[i].second != p[i].second) ok = false;
    }
    if (n > 1) {
      if (p[i].first == 0) {
        if (p[i].second == 0) ok = false;
      }
    }
  }
  vector<int> ans(n);
  for (int i = 0; i < (m); i++) {
    ans[p[i].first] = p[i].second;
  }
  if (ok) {
    for (int x : ans) cout << x;
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
