#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  int k[n];
  int res = pow(10, n - 1);
  int p = 10, q = 10, r = 10;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1) {
      p = min(c[i], p);
    } else if (s[i] == 2) {
      q = min(q, c[i]);
    } else {
      r = min(r, c[i]);
    }
  }
  int ans = 100 * (p % 10) + 10 * (q % 10) + (r % 10);
  if (ans >= res) {
    cout << ans;
  } else {
    cout << "-1";
  }
}
