#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
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; }
int main() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> p(m);
  for (long long i = 0; i < m; i++) {
    cin >> p[i].first >> p[i].second;
  }
  if (n > 1 && p[0].second == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (p[0].first != 1) {
    cout << -1 << endl;
    return 0;
  }
  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 << endl;
      return 0;
    }
  }
  vector<long long> ans(n, 0);
  for (long long i = 0; i < m; i++) {
    ans[p[i].first - 1] = p[i].second;
  }
  for (long long i = 0; i < n; i++) {
    cout << ans[i];
    if (i == n - 1) cout << endl;
  }
  return 0;
}
