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