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