#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  vector<int> A(N, -1);
  for (int i = 0; i < (int)(M); i++) {
    cin >> s[i] >> c[i];
  }
  int ans = -1;
  bool can = true;
  for (int i = 0; i < (int)(M); i++) {
    if (s[i] == 1 && c[i] == 0) {
      ans = -1;
      can = false;
      break;
    }
    if (A[s[i] - 1] == -1 || A[s[i] - 1] == c[i]) {
      A[s[i] - 1] = c[i];
    } else {
      ans = -1;
      can = false;
      break;
    }
  }
  if (!can) {
    cout << ans << endl;
  } else {
    for (int i = 0; i < (int)(N); i++) {
      if (N == 1 && M == 0 && A[i] == -1) A[i] = 0;
      if (i == 0 && A[i] == -1) A[i] = 1;
      if (A[i] == -1) {
        A[i] = 0;
      }
    }
    for (int i = 0; i < (int)(N); i++) {
      cout << A[i];
    }
    cout << endl;
  }
}
