#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};
  int flg[] = {0, 0, 0};
  for (int i = 0; i < m; i++) {
    int s, c;
    std::cin >> s >> c;
    if ((s == 1) && (c == 0)) {
      std::puts("-1");
      return 0;
    } else {
      if (flg[s - 1] == 0) {
        d[s - 1] = c;
        flg[s - 1] = 1;
      } else {
        d[s - 1] = std::min(d[s - 1], c);
      }
    }
  }
  if (flg[3 - n] != 1) {
    std::puts("-1");
    return 0;
  }
  ans = d[0] * 100 + d[1] * 10 + d[2];
  for (int i = 0; i < 3 - n; i++) {
    ans /= 10;
  }
  std::printf("%d\n", ans);
  return 0;
}
