#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, m, c, nr = 0, put1 = 11, put2 = 10, put3 = 100;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> s >> c;
    if (s == 1) put3 = min(put3, c);
    if (s == 2)
      put2 = min(put2, c);
    else
      put1 = min(put1, c);
  }
  if (put2 == 10) put2 = 0;
  if (put1 == 11) {
    put1 = 0;
  }
  if (put3 == 100) put3 = 0;
  if (put3 == 0) {
    cout << -1;
    return 0;
  }
  if (n == 3) cout << put3 << put2 << put1;
  if (n == 2) cout << put2 << put1;
  if (n == 1) cout << put1;
  return 0;
}
