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