#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> num(n, 0);
  num[0] = 1;
  vector<bool> f(n, false);
  int s, c;
  for (long long _ = 0; _ < (long long)(m); _++) {
    cin >> s >> c;
    if (s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (f[s - 1] && num[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    num[s - 1] = c;
    f[s - 1] = true;
  }
  for (long long i = 0; i < (long long)(n); i++) {
    cout << num[i];
  }
  cout << endl;
}
