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