#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> prime_factorize(long long n) {
  vector<pair<long long, long long>> res;
  for (long long p = 2; p * p <= n; ++p) {
    if (n % p != 0) continue;
    int num = 0;
    while (n % p == 0) {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1) res.push_back(make_pair(n, 1));
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> sv(m), cv(m);
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    sv[i] = s;
    cv[i] = c;
  }
  int ans = 1000;
  for (int i = 0; i < 1000; i++) {
    stringstream iss;
    iss << i;
    string str = to_string(i);
    bool flag = true;
    for (int j = 0; j < m; j++) {
      if (str.length() != n || str[sv[j]] != (char)(cv[j] + '0')) {
        flag = false;
      }
    }
    if (flag) {
      ans = min(ans, i);
    }
  }
  if (ans == 1000) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
