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