#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<char> c(M);
  for (int i = 0; i < (int)(M); ++i) {
    cin >> s[i] >> c[i];
    --s[i];
  }
  int MAX = 1;
  for (int i = 0; i < (int)(N); ++i) MAX *= 10;
  auto ok = [&](int n) {
    string t = to_string(n);
    for (int i = 0; i < (int)(M); ++i)
      if (t[s[i]] != c[i]) return false;
    return true;
  };
  for (int i = MAX / 10; i < MAX; ++i) {
    if (ok(i)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
