#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, -1);
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (ans[s] != -1 && ans[s] != c) {
      cout << -1 << '\n';
      return 0;
    }
    ans[s] = c;
  }
  if (n > 1 && ans[0] == 0)
    cout << -1 << '\n';
  else {
    for (int i = 0; i < n; ++i) {
      ans[i] = max(0, ans[i]);
      cout << ans[i];
    }
    cout << '\n';
  }
  return 0;
}
