#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> A(3, -1);
  int N, M;
  cin >> N >> M;
  if (N == 1 && M == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (N == 1 && M == 1) {
    cout << 0 << endl;
    return 0;
  }
  int a, b;
  ;
  for (int i = 0; i < (int)(M); i++) {
    cin >> a >> b;
    if (a == 1 && b == 0) {
      if (N == 1 && M == 1) {
        cout << 0 << endl;
        return 0;
      }
      cout << -1 << endl;
      return 0;
    }
    if (A[a - 1] != -1) {
      if (A[a - 1] == b) {
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
    A[a - 1] = b;
  };
  for (int i = 0; i < (int)(N); i++) {
    if (A[i] == -1 && i == 0) {
      cout << 1;
      continue;
    }
    if (A[i] == -1) {
      cout << 0;
      continue;
    }
    cout << A[i];
  }
  cout << endl;
}
