#include<bits/stdc++.h>

using namespace std;

int main() {
  int n, m, s, c;
  cin >> n >> m;
  vector<int> num(n, -1);
  while (m--) {
    cin >> s >> c;
    if (num[--s] != -1 && num[s] != c || n > 1 && !s && !c) {
      cout << -1 << '\n';
      return 0;
    }
    num[s] = c;
  }
  for (int i = 0; i < n; ++i)
    cout << (num[i] == -1 ? (n > 1 && !i) : num[i]);
  cout << '\n';
  return 0;
}