#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
bool prime(int x) {
  int i;
  if (x < 2) return 0;
  for (i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      return 0;
    }
  }
  return 1;
}
int a[1001], n, m, b[1001];
int c[1001];
int main() {
  int i;
  cin >> n >> m;
  for (i = 0; i < 1001; i++) c[i] = -1;
  for (i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (c[x] != -1 && c[x] != y || n != 1 && x == 1 && y == 0) {
      cout << -1;
      return 0;
    }
    c[x] = y;
  }
  for (i = 1; i <= n; i++) {
    if (c[i] == -1)
      cout << 0;
    else
      cout << c[i];
  }
  return 0;
}
