#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 5;
const long long mod = 1e9 + 7;
const long long N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve() {
  long long n, m;
  cin >> n >> m;
  set<long long> second;
  map<long long, set<long long>> un;
  map<long long, long long> u;
  for (long long i = 0; i < m; i++) {
    long long l, r;
    cin >> l >> r;
    un[l].insert(r);
  }
  vector<long long> ans(n);
  for (long long i = 0; i < 10; i++) {
    if (!(long long)un[i].size()) continue;
    if ((long long)un[i].size() > 1) {
      cout << "-1\n";
      return;
    }
    if (!u[*un[i].begin()]) {
      if (i > n) {
        cout << "-1\n";
        return;
      }
      ans[i - 1] = *un[i].begin();
      u[*un[i].begin()]++;
    }
  }
  if (n > 1 && ans[1] == 0 && ans[0] == ans[1]) {
    cout << "-1\n";
    return;
  }
  for (long long i = 0; i < n; i++) cout << ans[i];
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  while (t--) solve();
}
