#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, pos, num;
  scanf("%d %d", &n, &m);
  vector<int> s(n + 1, -1);
  bool ex = 0;
  int ver = n;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &pos, &num);
    if (s[pos - 1] == -1) {
      s[pos - 1] = num;
    } else if (s[pos - 1] == num)
      continue;
    else
      ex = 1;
    if (s[pos - 1] == 0) ver--;
  }
  if (ex or ver + m == n) return !printf("-1\n");
  for (int i = 0; i < n; i++) {
    if (s[i] == -1)
      cout << "0";
    else
      cout << s[i];
  }
}
