#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  long long ans = 0;
  map<long long, long long> mp;
  long long x, y;
  while (m--) {
    cin >> x >> y;
    if (mp.count(x) && mp[x] != y) {
      cout << -1;
      return 0;
    };
    if (x == 1 && y == 0) {
      cout << -1;
      return 0;
    };
    mp[x] = y;
  }
  if (!mp.count(1)) mp[1] = 1;
  for (long long i = 1; i < n + 1; ++i) {
    cout << mp[i];
  }
}
