#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < M; i++) s[i]--;
  vector<set<int>> digit(N);
  for (int i = 0; i < M; i++) digit[s[i]].insert(c[i]);
  for (int i = 0; i < N; i++) {
    if (digit[i].size() > 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  vector<int> ans(N, 0);
  for (int i = 0; i < N; i++) {
    if (digit[i].empty()) continue;
    ans[i] = *digit[i].begin();
  }
  if (N != 1 && ans[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) cout << ans[i];
  cout << endl;
  return 0;
}
