#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int num[4];
  for (int i = 1; i <= 3; i++) num[i] = -1;
  for (int i = 0; i < M; i++) {
    int s, c;
    scanf("%d %d", &s, &c);
    if (num[s] == -1 || num[s] == c) {
      num[s] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (num[1] == -1) num[N] = 1;
  if (num[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= N; i++) {
    if (num[i] == -1) num[i] = 0;
    printf("%d", num[i]);
  }
  printf("\n");
  return 0;
}
