#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[4];
  for (int i = 1; i < 4; i++) a[i] = 10;
  int N, M, index, num;
  cin >> N >> M;
  for (int i = 1; i <= M; i++) {
    cin >> index >> num;
    if (a[index] > num) a[index] = num;
  }
  for (int i = 1; i < 4; i++)
    if (a[i] == 10) a[i] = 0;
  if (N != 1 && a[1] == 0)
    cout << -1;
  else if (N == 1)
    cout << a[1];
  else if (N == 2)
    cout << a[1] * 10 + a[2];
  else
    cout << a[1] * 100 + a[2] * 10 + a[3];
}
