#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  int C[4] = {10, 10, 10, 10};
  bool S[4] = {};
  if (M == 0 && N != 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (S[s - 1] == true && C[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    if (s == 1 && c >= 0 && N != 1) {
      if (c == 0) {
        cout << -1 << endl;
        return 0;
      }
      S[0] = true;
      C[1] = min(C[1], c);
    }
    if (s == 2 && c >= 0) {
      S[1] = true;
      C[2] = min(C[1], c);
    }
    if (s == 3 && c >= 0) {
      S[2] = true;
      C[3] = min(C[2], c);
    }
  }
  for (int i = 0; i < 3; i++) {
    if (S[i] == false && i == 0 && N == 1)
      C[i + 1] = 0;
    else if (S[i] == false && i == 0)
      C[i + 1] = 1;
    else if (S[i] == false && i != 0)
      C[i + 1] = 0;
  }
  for (int i = 1; i <= N; i++) {
    cout << C[i];
  }
  cout << endl;
}
