#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
signed main() {
  vector<long long> v(3, INF);
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long s, c;
    cin >> s >> c;
    s--;
    if (v[s] != INF && v[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    v[s] = min(v[s], c);
    if (v[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (v[0] == INF && v[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (long long i = 0; i < 3; i++) {
    if (v[i] == INF) v[i] = 0;
  }
  long long ans = 0, t = 100;
  for (long long i = 0; i < 3; i++) {
    ans += v[i] * t;
    t /= 10;
  }
  cout << ans << endl;
  return 0;
}
