#include <bits/stdc++.h>
using namespace std;
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m), c(m);
  for (long long i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  if (m == 0) {
    if (n == 1) cout << 0 << endl;
    if (n == 2) cout << 11 << endl;
    if (n == 3) cout << 111 << endl;
    return 0;
  }
  for (long long i = 0; i < m - 1; i++) {
    for (long long j = 1; i + j < m; j++) {
      if (s.at(i) == s.at(i + j) && c.at(i) != c.at(i + j)) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  vector<long long> ans(n);
  ans.at(0) = 1;
  for (long long i = 0; i < m; i++) {
    ans.at(s.at(i) - 1) = c.at(i);
  }
  if (ans.at(0) == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (long long i = 0; i < n; i++) {
    cout << ans.at(i);
  }
  cout << endl;
}
