#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vi vec(n);
  for (int i = 0; i < m; i++) {
    int si, ci;
    cin >> si >> ci;
    si -= 1;
    if (vec.at(si) == 0)
      vec.at(si) = ci;
    else if (!(si == 0 && ci == 0))
      vec.at(si) = min(vec.at(si), ci);
  }
  if (vec.at(0) == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cout << vec.at(i);
  }
  cout << endl;
  return 0;
}
