#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const double PI = 3.1415926535897932;
const long long INF = 1 << 29;
bool comp(const pair<long long, long long> &a,
          const pair<long long, long long> &b) {
  return a.first < b.first;
}
void sort2vectors(vector<long long> &av, vector<long long> &bv) {
  long long n = av.size();
  vector<pair<long long, long long> > p(n);
  vector<long long> av2(n), bv2(n);
  for (long long i = 0; i < n; i++) p[i] = make_pair(av[i], bv[i]);
  sort(p.begin(), p.end(), comp);
  for (long long i = 0; i < n; i++) {
    av2[i] = p[i].first;
    bv2[i] = p[i].second;
  }
  av = av2;
  bv = bv2;
}
long long n, m;
vector<long long> s, c;
long long solve() {
  cin >> n >> m;
  s.resize(m);
  c.resize(m);
  bool first_keta = false;
  for (long long i = (0); i < (m); i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1) {
      first_keta = true;
    }
  }
  sort2vectors(s, c);
  for (long long i = (0); i < (m - 1); i++) {
    if (s[i] == s[i + 1] && c[i] != c[i + 1]) {
      cout << -1 << endl;
      return 0;
    }
  }
  vector<long long> kazu(n);
  for (long long i = (0); i < (n); i++) {
    kazu[i] = -1;
  }
  for (long long j = (0); j < (m); j++) {
    kazu[s[j] - 1] = c[s[j] - 1];
  }
  if (first_keta && kazu[0] != 0) {
    for (long long i = (0); i < (n); i++) {
      if (kazu[i] == -1) {
        cout << 0;
      } else {
        cout << kazu[i];
      }
    }
    cout << endl;
    return 0;
  }
  if (!first_keta) {
    cout << 1;
    for (long long i = 1; i < n; i++) {
      if (kazu[i] == -1) {
        cout << 0;
      } else {
        cout << kazu[i];
      }
    }
    cout << endl;
    return 0;
  }
  if (kazu[0] == 0 && n != 1) {
    cout << -1 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}
int main() {
  cout << std::fixed << std::setprecision(10);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long end_solve = solve();
  return (int)end_solve;
}
