#include <bits/stdc++.h>
using namespace std;
void pre() {}
void solve() {
  long long n, m;
  cin >> n >> m;
  long long a, b;
  string s;
  vector<long long> v;
  v.resize(n, 0);
  bool vis[n];
  for (long long i = 0; i < n; i++) vis[i] = false;
  for (long long i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    if (!vis[a]) {
      v[a] = b;
      vis[a] = true;
    } else {
      if (v[a] == b) {
      } else {
        cout << "-1" << '\n';
        return;
      }
    }
  }
  if (v[0] == 0) {
    cout << "-1" << '\n';
    return;
  }
  for (long long i = 0; i < n; i++) {
    cout << v[i];
  }
  cout << '\n';
}
signed main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  pre();
  long long tests = 1;
  while (tests--) {
    solve();
  }
  return 0;
}
