#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const long long LLINF = 1LL << 60;
int mod = 1000000007;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  int S[M], digit[M];
  for (int i = 0; i < M; i++) {
    int s, d;
    cin >> s >> d;
    S[i] = s - 1;
    digit[i] = d;
  }
  int pow10[] = {1, 10, 100, 1000};
  int dlim, ulim;
  ulim = pow10[N];
  if (N == 0)
    dlim = 0;
  else
    dlim = pow10[N - 1];
  for (int i = dlim; i < ulim; i++) {
    string s = to_string(i);
    bool ok = true;
    for (int j = 0; j < M; j++) {
      if (s[S[j]] - '0' != digit[j]) ok = false;
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
