#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, i, j;
  cin >> n >> m;
  long long ara[n];
  memset(ara, 0, sizeof(ara));
  for (i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    ara[x - 1] = min(ara[x - 1], y);
  }
  if (n == 1) {
    cout << ara[0] << endl;
  } else if (ara[0] == 0)
    cout << -1 << endl;
  else {
    for (i = 0; i < n; i++) cout << ara[i];
    cout << endl;
  }
  return 0;
}
