#include <bits/stdc++.h>
using namespace std;
inline long long next(void) {
  long long k;
  cin >> k;
  return k;
}
long long w[5];
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  for (int i = 0; i < 5; i++) w[i] = 1 << 30;
  while (m--) {
    long long a = next(), b = next();
    if (a == 1 && n == 1 && b == 0)
      w[a] = b;
    else if (a != 1 || (a == 1 && b != 0))
      w[a] = min(w[a], b);
  }
  if (w[1] == 1 << 30) {
    if (n == 1)
      cout << 0 << endl;
    else
      cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) cout << (w[i] == 1 << 30 ? 0 : w[i]);
  cout << endl;
  return 0;
}
