#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int main(void) {
  int N, M, ans = 0;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  int digit[4] = {0, 0, 0, 0};
  for (int i = 0; i < M; i++) {
    if (digit[s[i]] == 0) {
      digit[s[i]] = c[i];
    } else if (digit[s[i] < c[i]])
      digit[s[i]] = c[i];
    else
      break;
  }
  if (digit[1] == 0 && (N != 3 || N != 2))
    cout << -1 << endl;
  else if (digit[1] == 0 && digit[2] == 0 && digit[3] == 0)
    cout << -1 << endl;
  else {
    ans = digit[1] * 100 + digit[2] * 10 + digit[3];
    cout << ans << endl;
  }
  return 0;
}
