#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int answer = 0;
  int flag[N];
  for (int i = 0; i < N; i++) flag[i] = 10;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (s <= N) {
      flag[s - 1] = min(c, flag[s - 1]);
    }
  }
  for (int i = 0; i < N; i++) {
    if (flag[i] == 10) flag[i] = 0;
  }
  if (N == 1) {
    answer = flag[0];
    if (answer >= 0)
      cout << answer << endl;
    else
      cout << -1 << endl;
  } else if (N == 2) {
    answer = flag[0] * 10 + flag[1];
    if (answer - 10 >= 0)
      cout << answer << endl;
    else
      cout << -1 << endl;
  } else if (N == 3) {
    answer = flag[0] * 100 + flag[1] * 10 + flag[2];
    if (answer - 100 >= 0)
      cout << answer << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
