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