#include <bits/stdc++.h>
using namespace std;
int n, m, ans[5];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) ans[i] = -1;
  for (int i = 1, x, y; i <= m; ++i) {
    scanf("%d %d", &x, &y);
    if (~ans[x] && ans[x] != y) {
      puts("-1");
      return 0;
    }
    ans[x] = y;
  }
  if (!ans[1]) {
    puts("-1");
    return 0;
  }
  if (~ans[1])
    printf("%d", ans[1]);
  else
    putchar('1');
  for (int i = 2; i <= n; ++i)
    if (ans[i] == -1)
      putchar('0');
    else
      printf("%d", ans[i]);
  return 0;
}
