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