#include <bits/stdc++.h>
using namespace std;
int a[10], b[10];
int n, m, x, y;
int main() {
  cin >> n >> m;
  memset(a, 0x3f3f3f3f, sizeof(a));
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    a[x] = min(a[x], y);
  }
  if (n == 1) {
    if (a[1] == 0x3f3f3f3f)
      cout << -1;
    else
      cout << a[1];
  }
  if (n == 2) {
    if (a[1] == 0 || a[1] == 0x3f3f3f3f)
      cout << -1;
    else
      cout << a[1] * 10 + a[2];
  }
  if (n == 3) {
    if (a[1] == 0 || a[1] == 0x3f3f3f3f)
      cout << -1;
    else {
      if (a[3] != 0x3f3f3f3f)
        cout << a[1] * 100 + a[3];
      else
        cout << -1;
    }
  }
  return 0;
}
