#include <bits/stdc++.h>
using ll = long long;
int main(int argc, char** argv) {
  int n, m;
  std::cin >> n >> m;
  int ans = -1;
  int d[] = {0, 0, 0};
  if (n > m) {
    std::printf("%d\n", ans);
    return 0;
  }
  for (int i = 0; i < m; i++) {
    int s, c;
    std::cin >> s >> c;
    d[s - 1] = c;
  }
  std::printf("%d%d%d\n", d[0], d[1], d[2]);
  return 0;
}
