#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans(-1);
  size_t N, M;
  cin >> N >> M;
  int s100(0), s10(0), s1(0);
  switch (N) {
    case (3):
      s100 = 10;
    case (2):
      s10 = 10;
    case (1):
      s1 = 10;
    default:
      break;
  }
  for (size_t i = 0; i < M; ++i) {
    int si, ci;
    cin >> si >> ci;
    switch (si) {
      case (1):
        s100 = min(s100, ci);
        break;
      case (2):
        s10 = min(s10, ci);
        break;
      case (3):
        s1 = min(s1, ci);
        break;
      default:
        break;
    }
  }
  switch (N) {
    case (3):
      if (s100 != 10 && s100 != 0) {
        s10 = s10 == 10 ? 0 : s10;
        s1 = s1 == 10 ? 0 : s1;
        ans = s100 * 100 + s10 * 10 + s1;
      }
      break;
    case (2):
      if (s10 != 10 && s10 != 0) {
        s1 = s1 == 10 ? 0 : s1;
        ans = s10 * 10 + s1;
      }
      break;
    case (1):
      if (s1 != 10 && s1 != 0) ans = s1;
      break;
    default:
      break;
  }
  cout << ans << endl;
  return 0;
}
