#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / gcd(a, b);
}
vector<int> v;
int main() {
  int a, b, c, n, m;
  v.resize(3);
  v[0] = 0;
  v[1] = 0;
  v[2] = 0;
  cin >> n >> m;
  while (m--) {
    cin >> a >> b;
    if (v[a - 1] != 0 && v[a - 1] > b && b != 0)
      v[a - 1] = b;
    else if (b != 0)
      v[a - 1] = b;
  }
  if (v[0] == 0)
    cout << -1 << endl;
  else {
    cout << v[0];
    cout << v[1] << v[2] << endl;
  }
  return 0;
}
