#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  string ans(N, '0');
  vector<bool> changed(N, false);
  int s, c;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    s = s - 1;
    if (changed.at(s) && int(ans.at(s) - '0') != c) {
      cout << -1 << endl;
      return 0;
    } else if (!s && !c) {
      cout << -1 << endl;
      return 0;
    } else {
      ans.at(s) = char('0' + c);
      changed.at(s) = true;
    }
  }
  int res = 0;
  for (int i = 0; i < N; i++) res = res * 10 + int(ans.at(i) - '0');
  cout << res << endl;
}
