#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> c(M);
  for (int i = 0; i < M; i++) {
    cin >> c.at(i).first >> c.at(i).second;
  }
  sort(c.begin(), c.end());
  for (int i = 0; i < M - 1; i++) {
    if (c.at(i).first == 1 && c.at(i).second == 0 && N != 1) {
      printf("-1\n");
      exit(0);
    }
    if (c.at(i).first == c.at(i + 1).first) {
      if (c.at(i).second != c.at(i + 1).second) {
        printf("-1\n");
        exit(0);
      }
    }
  }
  if (c.at(M - 1).first == 1 && c.at(M - 1).second == 0 && N != 1) {
    printf("-1\n");
    exit(0);
  }
  vector<int> ans(N, 0);
  for (int i = 0; i < M; i++) {
    ans.at(c.at(i).first - 1) = c.at(i).second;
  }
  for (int i = 0; i < N; i++) {
    printf("%d", ans.at(i));
  }
  printf("\n");
}
