#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;
  }
  for (int i = 0; i < 1000; ++i) {
    if (to_string(i).length() != N) continue;
    int tmp = i;
    vector<int> d(1, tmp % 10);
    while (tmp > 1) {
      d.emplace_back(tmp % 10);
      tmp /= 10;
    }
    reverse(d.begin(), d.end());
    bool ok = true;
    for (auto x : P) {
      if (d[x.first - 1] != x.second) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
