#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  int ans[n];
  for (int64_t i = (0); i < (n); i++) ans[i] = 0;
  for (int64_t i = (0); i < (m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (ans[s] != 0 && ans[s] != c) {
      cout << -1 << endl;
      return;
    }
    ans[s] = c;
  }
  if (n != 1 && ans[0] == 0) {
    cout << -1 << endl;
    return;
  }
  for (int64_t i = (0); i < (n); i++) cout << ans[i];
  cout << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
