#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using namespace std;
int main() {
  int N, M;
  int si, ci;
  bool ans = false;
  cin >> N >> M;
  vector<pair<int, int>> p(M);
  for (ll i = 0; i < (M); ++i) cin >> p[i].first >> p[i].second;
  for (ll x = 0; x < (1000); ++x) {
    int keta = 1;
    int nx = x / 10;
    vector<int> d(1, x % 10);
    while (nx > 0) {
      keta++;
      d.push_back(nx % 10);
      nx /= 10;
    }
    if (keta != N) continue;
    bool ok = true;
    reverse(d.begin(), d.end());
    for (ll i = 0; i < (M); ++i) {
      if (d[p[i].first - 1] != p[i].second) ok = false;
    }
    if (ok) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
