#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, c;
  cin >> n >> m;
  vector<int> v(n, INT_MAX);
  while (m--) {
    cin >> s >> c;
    v[s - 1] = min(c, v[s - 1]);
  }
  if (n > 1 && v[0] == INT_MAX)
    cout << -1 << "\n";
  else {
    for (int i = 0; i < v.size(); i++)
      if (v[i] == INT_MAX) v[i] = 0;
    if (n > 1 && v[0] == 0)
      cout << -1 << "\n";
    else {
      for (int i : v) cout << i;
    }
  }
  return 0;
}
