#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  int a, b;
  int ans[N];
  for (int i = 0; i < N; i++) {
    ans[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    if (ans[a - 1] == 0 || ans[a - 1] == b) {
      ans[a - 1] = b;
    } else {
      printf("-1");
    }
  }
  for (int i = 0; i < N; i++) {
    printf("%d", ans[i]);
  }
}
