#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> v(n, 0);
  for (int i = 0, pos, val; i < m; i++) {
    cin >> pos >> val;
    if (v[pos - 1] == 0)
      v[pos - 1] = val;
    else {
      if (v[pos - 1] > val) v[pos - 1] = val;
    }
  }
  if (v[0] == 0)
    cout << -1 << endl;
  else {
    for (auto x : v) cout << x;
  }
  return 0;
}
