#include <bits/stdc++.h>
using namespace std;
int n, m;
bool ok = true;
int main() {
  cin >> n >> m;
  vector<pair<int, int>> p(n);
  for (long long i = (long long)(0); i < (long long)(m); i++) {
    cin >> p[i].first >> p[i].second;
  }
  for (long long aH = (long long)(0); aH < (long long)(1000); aH++) {
    int keta = 1;
    int naH = aH / 10;
    vector<int> bH(1, aH % 10);
    while (naH) {
      keta++;
      bH.push_back(naH % 10);
      naH / 10;
    }
    if (keta != n) {
      ok = false;
    }
    reverse(bH.begin(), bH.end());
    for (long long i = (long long)(0); i < (long long)(m); i++) {
      if (bH[p[i].first - 1] != p[i].second) {
        ok = false;
      }
    }
    if (ok) {
      cout << aH << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
