#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x %= p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  {
    int n, m, f = 0;
    ;
    cin >> n >> m;
    int a[n + 1];
    memset(a, 0, sizeof(a));
    map<int, int> ma;
    for (int i = 0; i < m; i++) {
      long long x, y;
      cin >> x >> y;
      if (x == 1 && y == 0) {
        f = 1;
      }
      if ((ma[x] && ma[x] != y)) {
        f = 1;
      }
      ma[x] = y;
    }
    if (f == 0) {
      for (auto it = ma.begin(); it != ma.end(); it++) {
        a[it->first] = it->second;
      }
    }
    if (f) {
      cout << -1 << "\n";
    } else {
      for (int i = 1; i <= n; i++) {
        cout << a[i];
      }
      cout << "\n";
    }
  }
  return 0;
}
