#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N, M, t = 0;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int64_t i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  for (int64_t i = pow(10, N - 1); i < pow(10, N); i++) {
    t = 0;
    for (int64_t j = 0; j < M; j++) {
      if (i / (int)pow(10, N - s.at(j)) -
              (i / (int)pow(10, N - s.at(j) + 1)) * 10 !=
          c.at(j)) {
        t = 1;
        break;
      }
    }
    if (t == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
