#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s, c;
  int value[3] = {0, 0, 0};
  bool isset[3] = {false, false, false};
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (isset[s - 1] == false) {
      value[s - 1] = c;
      isset[s - 1] = true;
    } else {
      if (value[s - 1] > c) {
        value[s - 1] = c;
      }
    }
  }
  int ans = value[0] * 100 + value[1] * 10 + value[2];
  if (n == 3 && ans < 100) ans = -1;
  if (n == 2 && ans < 10 && ans >= 100) ans = -1;
  if (n == 1 && ans >= 10) ans = -1;
  cout << ans << endl;
}
