#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  for (int i = 0; i < n; i++) {
    a[i] = 11;
  }
  while (m--) {
    int pos, num;
    cin >> pos >> num;
    a[pos - 1] = min(num, a[pos - 1]);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 11) a[i] = 0;
  }
  if (a[0] == 0) {
    cout << -1;
  } else {
    for (int ar : a) {
      cout << ar;
    }
  }
  return 0;
}
