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