#include <bits/stdc++.h>
using namespace std;
int n, m, s, c, d[5];
int main() {
  int i;
  cin >> n >> m;
  for (i = 1; i <= n; i++) d[i] = -1;
  while (m--) {
    cin >> s >> c;
    if (d[s] > -1 && d[s] != c) return puts("-1") * 0;
    d[s] = c;
  }
  if (n > 1 && d[1] == 0) return puts("-1") * 0;
  for (i = 1; i <= n; i++) {
    if (d[i] > -1)
      cout << d[i];
    else
      cout << 0;
  }
  return 0;
}
