#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 < (int)(m); i++) {
    cin >> p[i].first >> p[i].second;
  }
  vector<int> ans(n);
  bool ok = true;
  for (int i = 0; i < (int)(m); i++) {
    if (i == 0) {
      if (p[i].second == 0) {
        ok = false;
        break;
      }
    }
    bool fin = false;
    for (int j = 0; j < (int)(i); j++) {
      if (p[i].first == p[j].first && p[i].second != p[j].second) {
        ok = false;
        fin = true;
        break;
      }
    }
    if (fin) break;
    ans[p[i].first - 1] = p[i].second;
  }
  if (ok) {
    for (int i = 0; i < (int)(n); i++) cout << ans[i];
  } else {
    cout << -1;
  }
  cout << "\n";
}
