#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  string s = "0000";
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    s[a] = b + '0';
  }
  int i;
  for (i = 1; i <= n; i++) {
    if (s[i] != '0') break;
  }
  if ((int)s.size() - i == n) {
    for (int j = i; j <= n; j++) cout << s[j];
  } else
    cout << -1 << endl;
}
