#include <bits/stdc++.h>
using namespace std;
int num[5];
bool visit[5];
int main(void) {
  int n, m, f = 1;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int s, c;
    scanf("%d%d", &s, &c);
    if (visit[s] == 0)
      visit[s] = 1, num[s] = c;
    else if (num[s] != c)
      f = 0;
  }
  if (f == 0) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1; i <= 3; i++) {
    if (num[i] == 0) {
      if (f == 1) {
        if (visit[i] == 0)
          continue;
        else {
          printf("-1\n");
          break;
        }
      } else
        printf("0");
    } else
      printf("%d", num[i]), f = 2;
  }
  return 0;
}
