#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> s(M), c(M), rec(N + 1, -1);
  for (long long i = (0); i < (long long)(M); i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (rec[s[i]] != -1 && rec[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    rec[s[i]] = c[i];
  }
  for (long long i = (1); i < (long long)(N + 1); i++) {
    if (rec[i] != -1)
      cout << rec[i];
    else
      cout << 0;
  }
  cout << endl;
  return 0;
}
