#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  int min = 0;
  if ((N == 2) || (N == 3)) {
    min = pow(10, N - 1);
  }
  if (M == 0) {
    cout << min << endl;
    return 0;
  }
  for (int n = 0; n < 1000; n++) {
    string n_str = to_string(n);
    int len = (int)(n_str.length());
    if (len != N) continue;
    if (len == 1) n_str = "00" + n_str;
    if (len == 2) n_str = "0" + n_str;
    bool ok = true;
    for (int i = 0; i < M; i++) {
      if (n_str[s[i] - 1] != (char)('0' + c[i])) {
        ok = false;
      }
    }
    if (ok) {
      cout << n << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
