#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int num[N];
  for (int i = 0; i < N; i++) {
    num[i] = -1;
  }
  int Si, Ci;
  int flag = 0;
  for (int i = 0; i < M; i++) {
    cin >> Si >> Ci;
    if (num[Si - 1] != -1 && num[Si - 1] != Ci) {
      flag = -1;
    }
    num[Si - 1] = Ci;
  }
  if (N == 1) {
    if (flag == -1) {
      cout << -1 << endl;
    } else if (num[0] == -1) {
      cout << 0 << endl;
    } else {
      cout << num[0] << endl;
    }
  } else {
    if (num[0] == 0) flag = -1;
    if (num[0] == -1) num[N - 1] = 1;
    for (int i = 1; i < N - 1; i++) {
      if (num[i] == -1) num[i] = 0;
    }
    if (flag == -1) {
      cout << -1 << endl;
    } else {
      for (int i = 0; i < N; i++) {
        cout << num[i];
      }
      cout << endl;
    }
  }
}
