#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] = 10;
  }
  while (M--) {
    int p, d;
    cin >> p >> d;
    A[p - 1] = min(A[p - 1], d);
  }
  for (int i = 0; i < N; i++) {
    A[i] = A[i] % 10;
  }
  if (A[0] == 0) {
    cout << -1;
    return 0;
  } else {
    for (auto x : A) cout << x;
  }
  return 0;
}
