#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long m, n, aa[110000][10], cnt = 0, ab[10];
pair<long long, long long> p[220000];
string s, ss[220000], x;
char c;
signed main() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p, p + m);
  for (long long i = 0; i < m - 1; i++) {
    if (p[i].first == p[i + 1].first && p[i].second != p[i + 1].second) {
      cout << -1;
      return 0;
    }
  }
  if (p[0].first == 1 && p[0].second == 0) {
    if (n == 1) {
      cout << 0;
    } else {
      cout << -1;
    }
    return 0;
  }
  for (long long i = 0; i < m; i++) {
    ab[p[i].first - 1] = p[i].second;
  }
  if (ab[0] == 0) {
    cout << 1;
  } else {
    cout << ab[0];
  }
  for (long long i = 0; i < n - 1; i++) {
    cout << ab[i + 1];
  }
}
