#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[m][2];
  int b[5] = {0};
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> a[i][j];
      b[a[i][0] - 1] = a[i][1];
    }
  }
  int cnt = 0;
  for (int i = 0; i < 5; i++) {
    if (b[i] != 0) {
      cnt += b[i] * pow(10, 5 - i - 1);
    }
  }
  int x;
  x = n * 100 + 1;
  for (int i = 1; i < 5; i++) {
    if (cnt % (int)pow(10, i) != 0) {
      cnt /= pow(10, i - 1);
      break;
    }
  }
  if (cnt >= x)
    cout << cnt;
  else
    cout << -1;
}
