#include <bits/stdc++.h>
template <class T>
inline void read(T &x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    f |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  x = f ? -x : x;
  return;
}
int ans[10];
int n, m;
bool is[10];
int main() {
  read(n), read(m);
  for (int i = 1, s, c; i <= m; ++i) {
    read(s), read(c);
    if (is[s] && ans[s] != c) {
      puts("-1");
      return 0;
    }
    is[s] = true;
    ans[s] = c;
  }
  if (n > 1 && ans[1] == 0) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i <= n; ++i) printf("%d", ans[i]);
  puts("");
  return 0;
}
