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