#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> q(n, -1);
  long long s, c;
  for (long long i = 0; i < m; ++i) {
    cin >> s >> c;
    s--;
    if (q[s] != -1 && q[s] != c) return cout << "-1", 0;
    q[s] = c;
  }
  if (q[0] == -1) q[0] = 1;
  if (q[0] == 0) return cout << "-1", 0;
  for (auto &i : q)
    if (i == -1) i = 0;
  for (auto &i : q) cout << i;
  return 0;
}
