#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  string ans = "";
  for (int i = 0; i < n; i++) ans += "0";
  for (int i = 0; i < m; i++) {
    int loc = s[i] - 1;
    ans[loc] = c[i];
  }
  int ans_num = stoi(ans);
  ans = to_string(ans_num);
  if (ans.length() != n) {
    cout << -1 << endl;
    return 0;
  }
  bool ok = true;
  for (int i = 0; i < m; i++) {
    int loc = s[i] - 1;
    if (ans[loc] != c[i]) ok = false;
  }
  if (ok) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
