#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  bool isPossible = true;
  int *numArray = new int[N];
  for (int i = 0; i < N; i++) {
    numArray[i] = -1;
  }
  for (int i = 0; i < M; i++) {
    int si, ci;
    cin >> si >> ci;
    if (numArray[si - 1] == -1 || numArray[si - 1] == ci) {
      numArray[si - 1] = ci;
    } else {
      isPossible = false;
    }
  }
  if (N != 1 && numArray[0] == -1) {
    numArray[0] = 1;
  } else if (numArray[0] == -1) {
    numArray[0] = 0;
  }
  for (int i = 1; i < N; i++) {
    if (numArray[i] == -1) numArray[i] = 0;
  }
  if (isPossible == false || numArray[0] == 0) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < N; i++) {
      cout << numArray[i];
    }
    cout << endl;
  }
  return 0;
}
