#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long N, M;
  cin >> N >> M;
  vector<long long> ans(M, -1);
  bool flag = true;
  for (long long i = (0), i_len = (M); i < i_len; ++i) {
    long long s, c;
    cin >> s >> c;
    s--;
    if (s == 0 && c == 0) {
      flag = false;
    }
    if (ans[s] == -1 || ans[s] == c) {
      ans[s] = c;
    } else {
      flag = false;
    }
  }
  if (flag) {
    for (long long i = (0), i_len = (M); i < i_len; ++i) {
      cout << (ans[i] == -1 ? 0 : ans[i]);
    }
    cout << "\n";
  } else {
    cout << "-1\n";
  }
  return 0;
}
