#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const long long mod = 1e9 + 7;
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 / gcd(a, b) * b; }
long long powMod(long long n, long long k, long long m) {
  if (k == 0) {
    return 1;
  } else if (k % 2 == 1) {
    return powMod(n, k - 1, m) * n % m;
  } else {
    long long t = powMod(n, k / 2, m);
    return t * t % m;
  }
}
int main() {
  long long n, m;
  cin >> n >> m;
  if (m == 0) {
    if (n == 1) {
      cout << 0 << endl;
      return 0;
    } else if (n == 2) {
      cout << 10 << endl;
      return 0;
    } else {
      cout << 100 << endl;
      return 0;
    }
  }
  string ans = "";
  for (long long i = 0; i < (n); ++i) {
    ans += "0";
  }
  vector<pair<long long, long long>> v(m);
  for (long long i = 0; i < (m); ++i) {
    long long s, c;
    cin >> s >> c;
    v[i] = make_pair(s, c);
  }
  sort((v).begin(), (v).end());
  long long preF = 0;
  long long preS = -1;
  for (long long i = 0; i < (m); ++i) {
    if (v[i].first == preF && v[i].second != preS) {
      cout << -1 << endl;
      return 0;
    } else {
      preF = v[i].first;
      preS = v[i].second;
      ans[v[i].first - 1] = v[i].second + '0';
    }
  }
  if (ans[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
}
