#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, M;
  cin >> N >> M;
  vector<pair<ll, ll>> order(M);
  for (ll i = 0; i < M; i++) {
    cin >> order[i].first >> order[i].second;
  }
  for (ll i = 0; i < 1000; i++) {
    bool flag = true;
    string str = to_string(i);
    for (ll i = 0; i < M; i++) {
      if (str.length() < order[i].first ||
          str.substr(order[i].first - 1, 1) != to_string(order[i].second))
        flag = false;
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
