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