#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chmin(T &a, T b) {
  a = min(a, b);
}
template <class T>
inline void chmax(T &a, T b) {
  a = max(a, b);
}
long long N, M;
long long s[5];
char c[5];
signed main() {
  cin >> N >> M;
  for (long long i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  long long mi, mx;
  if (N == 1) {
    mi = 1, mx = 9;
  } else if (N == 2) {
    mi = 10, mx = 99;
  } else {
    mi = 100, mx = 999;
  }
  for (long long i = mi; i <= mx; i++) {
    string t = to_string(i);
    for (long long j = 0; j < M; j++) {
      if (t[s[j]] != c[j]) {
        goto ng;
      }
    }
    cout << i << endl;
    return 0;
  ng:;
  }
  cout << -1 << endl;
}
