#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;
  vector<pair<int, int>> cp = p;
  sort((cp).begin(), (cp).end());
  int keta = cp[m - 1].first;
  bool is0 = false;
  for (int i = 0; i < (int)(m); i++) {
    if (cp[i].first == keta && cp[i].second == 0) {
      is0 = true;
      break;
    }
  }
  if (is0)
    ok = false;
  else {
    for (int i = 0; i < (int)(m); i++) {
      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;
    }
  }
  int num = 0;
  if (ok) {
    for (int i = 0; i < (int)(n); i++) {
      num += ans[i] * pow(10, n - 1 - i);
    }
  } else {
    num = -1;
  }
  cout << num << "\n";
}
