#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  int n, m;
  scanf("%d%d", &n, &m);
  char res[5];
  for (int i = 0; i < n; i++) res[i] = '0';
  int lastc[5] = {-1, -1, -1, -1, -1}, cnt = 0;
  for (int i = 0; i < m; i++) {
    int s, c;
    scanf("%d%d", &s, &c);
    if (lastc[--s] != -1) {
      if (lastc[s] == c) continue;
      puts("-1");
      return 0;
    }
    if (s == 0 && c == 0) {
      puts(n == 1 ? "0" : "-1");
      return 0;
    }
    lastc[s] = c, cnt++;
    res[s] = c + '0';
  }
  if (cnt > n) {
    puts("-1");
    return 0;
  }
  if (n == 1) {
    puts("0");
    return 0;
  }
  if (res[0] == '0') res[0] = '1';
  puts(res);
  return 0;
}
