#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  pair<long long, long long> s[m];
  long long ans = -1;
  for (long long i = 0; i < m; i++) {
    cin >> s[i].first >> s[i].second;
    if (s[i].first > n) {
      cout << -1 << '\n';
      return 0;
    }
  }
  long long lm = 1;
  for (long long p = 0; p < n + 1; p++) {
    lm *= 10;
  }
  lm--;
  for (long long i = 0; i <= lm; i++) {
    long long dg = 0;
    long long temp = i;
    vector<long long> v;
    while (temp > 0) {
      dg++;
      v.push_back(temp % 10);
      temp /= 10;
    }
    reverse(v.begin(), v.end());
    if (dg != n) continue;
    bool f = true;
    for (long long j = 0; j < m; j++) {
      if (v[s[j].first - 1] != s[j].second) f = false;
    }
    if (f) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << ans << '\n';
  return 0;
}
