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