#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<int> v(n);
  bool can = true;
  for (int i = 0; i < n; i++) {
    v[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    int s, c;
    scanf("%d %d", &s, &c);
    if (v[s - 1] == -1 || v[s - 1] == c) {
      v[s - 1] = c;
    } else {
      can = false;
    }
  }
  if (v[0] == 0 && (int)v.size() > 1) {
    can = false;
  }
  for (int i = 0; i < n; i++) {
    if (v[i] == -1) {
      v[i] = 0;
    }
  }
  if (can) {
    for (int i = 0; i < n; i++) {
      if (i == 0 && v[i] == 0) {
        continue;
      } else {
        printf("%d", v[i]);
      }
    }
  } else {
    printf("%d", -1);
  }
}
