#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long MOD = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  vi s(m);
  vi c(m);
  for (int i = 0; i < (int)(m); i++) {
    cin >> s.at(i) >> c.at(i);
  }
  int ans = -1;
  vi ans2(n, 0);
  for (int i = 0; i < (int)(m); i++) {
    ans2.at(s.at(i) - 1) = c.at(i);
  }
  bool fl = true;
  for (int i = 0; i < (int)(m); i++) {
    for (int j = 0; j < (int)(m); j++) {
      if (i == j) continue;
      if (s.at(i) == s.at(j)) {
        if (c.at(i) != c.at(j)) {
          cout << ans << endl;
          fl = false;
          break;
        }
      }
    }
    if (fl == false) break;
  }
  if (n == 1 && ans2.at(0) == 0) {
    cout << ans << endl;
    fl = false;
  }
  if (ans2.at(0) == 0) {
    ans2.at(0) = 1;
  }
  if (fl) {
    for (int i = 0; i < n; i++) {
      cout << ans2.at(i);
    }
    cout << endl;
  }
}
