#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > v(m);
  for (int i = 0; i < (m); i++) {
    int a, b;
    cin >> a >> b;
    --a;
    v[i] = make_pair(a, b);
  }
  sort(v.begin(), v.end());
  vector<int> ans(n);
  bool ok = true;
  int befidx = -1;
  int befitem = -1;
  for (int i = 0; i < (m); i++) {
    if (v[i].first == 0 && v[i].second == 0 ||
        (v[i].first == befidx && v[i].second != befitem)) {
      ok = false;
      break;
    } else {
      ans[v[i].first] = v[i].second;
      befidx = v[i].first;
      befitem = v[i].second;
    }
  }
  if (ans[0] == 0) ans[0] = 1;
  for (int i = 1; i <= n - 1; i++) {
    if (ans[i] == 0) ans[i] = 0;
  }
  if (ok) {
    for (int i = 0; i < (n); i++) cout << ans[i];
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
