#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > p(m);
  for (int i = 0; i < (m); ++i) cin >> p[i].first >> p[i].second;
  sort(p.rbegin(), p.rend());
  vector<int> x(n, 0);
  for (int i = 0; i < (m); ++i) {
    if (p[i].first == 1 && p[i].second == 0) {
      cout << "-1";
      return 0;
    }
    if (x[p[i].first - 1] == 0) {
      x[p[i].first - 1] = p[i].second;
      continue;
    }
    if (x[p[i].first - 1] != 0) {
      if (x[p[i].first - 1] != p[i].second) {
        cout << "-1";
        return 0;
      }
    }
  }
  if (x[n - 1] == 0) x[n - 1] = 1;
  for (int i = 0; i < (n); ++i) cout << x[i];
  return 0;
}
