#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a = 10, b = 10, c = 10, p, q;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> p >> q;
    if (p == 1)
      a = min(a, q);
    else if (p == 2)
      b = min(b, q);
    else if (p == 3)
      c = min(c, q);
  }
  if (a == 0)
    cout << "-1\n";
  else if (a != 10 && b != 10 && c != 10)
    cout << a << b << c << "\n";
  else if (b != 10 && c != 10)
    cout << "1" << b << c << "\n";
  else if (a != 10 && b != 10)
    cout << a << b << "0\n";
  else if (a != 10 && c != 10)
    cout << a << "0" << c << "\n";
  return 0;
}
