#include <bits/stdc++.h>
using namespace std;
typedef struct {
  int s;
  int c;
} num_t;
int cmp(const void *p, const void *q) {
  return ((num_t *)p)->s - ((num_t *)q)->s;
}
int main() {
  int N, M;
  cin >> N >> M;
  int s[M];
  int c[M];
  int ans[N];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  num_t lst[M];
  for (int i = 0; i < M; i++) {
    lst[i].s = s[i];
    lst[i].c = c[i];
  }
  qsort(lst, M, sizeof(num_t), cmp);
  if (lst[0].s == 1 && lst[0].c == 0) {
    if (N == 1) {
      cout << "0" << endl;
      return 0;
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    ans[i] = 0;
  }
  ans[0] = 1;
  for (int i = 0; i < M; i++) {
    if (i != 0 && lst[i - 1].s == lst[i].s) {
      if (lst[i - 1].c != lst[i].c) {
        cout << "-1" << endl;
        return 0;
      }
    }
    ans[lst[i].s - 1] = lst[i].c;
  }
  for (int i = 0; i < N; i++) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
