#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n, 0);
  v[0] = 1;
  map<int, int> q;
  vector<pair<int, int> > p(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    p[i] = make_pair(a, b);
  }
  for (int i = 0; i < m; i++) {
    if ((p[i].first == 1) && (p[i].second == 0)) {
      cout << -1;
      return 0;
    } else if (!q[p[i].first]) {
      v[p[i].first - 1] = p[i].second;
      q[p[i].first] = 1;
    } else if ((q[p[i].first]) && (v[p[i].first - 1] != p[i].second)) {
      cout << -1;
      return 0;
    }
  }
  for (int x : v) cout << x;
  return 0;
}
