#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, f = 0;
  cin >> n >> m;
  int a[n];
  fill(a, a + n, 0);
  a[0] = 1;
  vector<pair<int, int> > v;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v.push_back(make_pair(x, y));
    if (v[i].first == 1 && v[i].second == 0) {
      f = 1;
    }
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < m - 1; i++) {
    if ((v[i].first == v[i + 1].first && v[i].second != v[i + 1].second)) {
      f = 1;
    }
  }
  for (int i = 0; i < m; i++) {
    a[v[i].first - 1] = v[i].second;
  }
  if (f == 1) {
    cout << "-1";
  } else {
    for (int i = 0; i < n; i++) {
      cout << a[i];
    }
  }
  cout << endl;
  return 0;
}
