#include <bits/stdc++.h>
using namespace std;
int N = 0;
int M = 0;
int main(void) {
  cin >> N >> M;
  int Num[N];
  int s[N];
  int c[N];
  int i = 0;
  while (cin >> s[i] >> c[i]) {
    i++;
  }
  for (i = 0; i < N; i++) {
    Num[i] = 0;
  }
  for (i = 0; i < N; i++) {
    if (Num[s[i] - 1] != 0) {
      cout << -1;
      return 0;
    }
    Num[s[i] - 1] = c[i];
  }
  if (Num[0] == 0) {
    cout << -1;
  } else {
    for (int i = 0; i < N; i++) {
      cout << Num[i];
    }
  }
}
