#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000007;
const long long MOD = 1000000007;
long long n, m;
bool judge(long long i, vector<long long> const& s,
           vector<long long> const& c) {
  bool flag = true;
  long long keta = 0;
  long long buf = i;
  vector<long long> kakuketa;
  while (buf > 0) {
    kakuketa.push_back(buf % 10);
    keta++;
    buf /= 10;
  }
  kakuketa.push_back(0);
  reverse(kakuketa.begin(), kakuketa.end());
  if (keta != n) flag = false;
  for (long long j = 0; j < m; ++j) {
    if (kakuketa[s[j]] != c[j]) {
      flag = false;
    }
  }
  return flag;
}
signed main() {
  cin >> n >> m;
  vector<long long> s(m);
  vector<long long> c(m);
  for (long long i = 0; i < m; ++i) cin >> s[i] >> c[i];
  long long sup = 1000;
  if (n == 2) sup = 100;
  if (n == 1) sup = 10;
  for (long long i = 0; i < sup; ++i) {
    if (judge(i, s, c)) {
      cout << i << endl;
      break;
    }
    if (i == sup - 1) {
      cout << -1 << endl;
    }
  }
  return 0;
}
