#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> used(n), ans(n);
  int s, c;
  bool ok = true;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    s--;
    if (used[s] && c != ans[s]) ok = false;
    used[s] = 1;
    ans[s] = c;
  }
  if (used[0] && ans[0] == 0) ok = false;
  if (ok) {
    if (ans[0] == 0) ans[0] = 1;
    for (int i = 0; i < n; i++) cout << ans[i];
  } else
    cout << -1;
  return 0;
}
