#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] = -1;
  for (int i = 0; i < M; i++) {
    int c, s;
    cin >> c >> s;
    c--;
    if (A.at(c) != -1) {
      if (A.at(c) == s)
        continue;
      else {
        cout << -1 << endl;
        return 0;
      }
    } else
      A.at(c) = s;
  }
  if (A.at(0) == -1) A.at(0) = 1;
  if (A.at(0) == 0 && N >= 2) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    if (A.at(i) == -1) A.at(i) = 0;
    cout << A.at(i);
  }
}
