#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  bool fl = true;
  for (int i = 0; i < M; i++) {
    if (N != 1 && c[i] == 0 && s[i] == 1) fl = false;
    for (int j = i + 1; j < M; j++) {
      if (s[i] == s[j] && c[i] != c[j]) fl = false;
    }
  }
  if (!fl) {
    cout << -1 << endl;
    return 0;
  }
  int a[N];
  for (int i = 0; i < N; i++) {
    a[i] = -1;
  }
  for (int i = 0; i < M; i++) {
    a[s[i] - 1] = c[i];
  }
  for (int i = 0; i < N; i++) {
    if (a[i] == -1) a[i] = 0;
    cout << a[i];
  }
  cout << endl;
  return 0;
}
