#include <bits/stdc++.h>
using namespace std;
int n, m, num[4] = {0};
bool ans = 1, used[4] = {0};
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1, s, c; i <= m; ++i) {
    scanf("%d %d", &s, &c);
    if (num[s - 1] && c != num[s - 1])
      ans = 0;
    else
      num[s - 1] = c, used[s - 1] = 1;
  }
  if (ans && !(!num[0] && used[0])) {
    if (!num[0]) {
      if (n == 1)
        puts("0");
      else {
        num[0] = 1;
        for (int i = 0; i < n; ++i) putchar(num[i] + 48);
        putchar('\n');
      }
    } else {
      for (int i = 0; i < n; ++i) putchar(num[i] + 48);
      putchar('\n');
    }
  } else
    puts("-1");
  return 0;
}
