#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char *argv[]) {
  int N, M, s, c;
  cin >> N >> M;
  pair<int, int> sc[M];
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    sc[i] = make_pair(s, c);
  }
  sort(sc, sc + M);
  if (N > 1) {
    for (int i = 0; i < M; i++) {
      if (sc[i].first == 1 && sc[i].second == 0) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  for (int i = 1; i < M; i++) {
    if (sc[i - 1].first == sc[i].first && sc[i - 1].second != sc[i].second) {
      cout << "-1" << endl;
      return 0;
    }
  }
  int index = 1;
  for (int i = 1; i < M; i++) {
    if (sc[i].first > index) {
      printf("0");
      index++;
    }
    if (sc[i].first == index) {
      printf("%d", sc[i].second);
      index++;
    }
  }
  putchar('\n');
  return 0;
}
