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