#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a, b;
  bool judge = false;
  vector<int> ans(n, 0);
  vector<bool> alr(n, false);
  bool huka = false;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (alr[a - 1] == false) {
      alr[a - 1] = true;
      ans[a - 1] = b;
    }
    if (alr[a - 1] && ans[a - 1] != b) {
      judge = true;
    }
    if (a == 1 && b == 0) huka = true;
  }
  if (ans[0] == 0) ans[0] = 1;
  if (huka || judge)
    cout << -1 << endl;
  else {
    for (int i = 0; i < n; i++) {
      cout << ans[i];
    }
  }
}
