#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M + 1);
  vector<int> C(M + 1);
  for (int i = 0; i < M; i++) {
    cin >> S.at(i) >> C.at(i);
  }
  bool judge = false;
  for (int i = pow(10, N - 1); i < pow(10, N); i++) {
    string s = to_string(i);
    for (int j = 0; j < M; j++) {
      char sx = s.at(S.at(j) - 1);
      char c = C.at(j);
      if (sx != c)
        judge = false;
      else
        judge = true;
    }
    if (judge) {
      cout << i << endl;
      break;
    }
  }
  if (judge = false) cout << -1 << endl;
}
