#include <bits/stdc++.h>
using namespace std;
int dirx[] = {1, -1, 0, 0}, diry[] = {0, 0, 1, -1};
long long bigmod(long long x, long long p) {
  long long res = 1;
  while (p) {
    if (p & 1) res = (res * x) % 1000000000;
    x = (x * x) % 1000000000;
    p >>= 1;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> inp(n + 1, -1);
  bool nposi = 0;
  while (m--) {
    int x, y;
    cin >> x >> y;
    if (inp[x] != -1 && inp[x] != y) nposi = 1;
    inp[x] = y;
    if (x == 1 && !y && n != 1) nposi = 1;
  }
  if (nposi) return cout << -1, 0;
  for (int i = 1; i <= n; i++) cout << (inp[i] == -1 ? 0 : inp[i]);
  return 0;
}
