#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> N(n, 0);
  int flag = 0;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (N[s - 1] == 0)
      N[s - 1] = c;
    else {
      if (N[s - 1] > c) N[s - 1] = c;
    }
  }
  if ((N[0] == 0) && (n != 1)) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cout << N[i];
  }
  return 0;
}
