#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> v(m);
  vector<long long> ans(3, 0);
  for (long long i = 0; i < m; i++) {
    cin >> v[i].first >> v[i].second;
    v[i].first--;
    ans[v[i].first] = v[i].second;
  }
  long long flg = 1;
  for (long long i = 0; i < m; i++) {
    if (v[i].first >= n) {
      cout << -1;
      return 0;
    }
    if (ans[v[i].first] != v[i].second) {
      flg = 0;
    }
  }
  if (flg == 1) {
    if (n > 1 && ans[0] == 0) {
      cout << -1;
      return 0;
    }
    for (long long i = 0; i < n; i++) {
      cout << ans[i];
    }
  } else {
    cout << -1;
  }
}
