#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, pos, num;
  scanf("%d %d", &n, &m);
  vector<int> s(n + 1, 11);
  bool ex = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &pos, &num);
    if (pos > n) ex = 1;
    if (pos == 1 && num == 0) continue;
    s[pos - 1] = min(s[pos - 1], num);
  }
  int rep = 0;
  while (rep < n) s[rep] == 11 ? s[rep++] = 0 : rep++;
  if ((s[0] == 0 && n > 1) || ex || m == 0) return !printf("-1\n");
  for (int i = 0; i < n; i++) {
    cout << s[i];
  }
}
