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