#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, m, pos, num;
  cin >> n >> m;
  vector<long long> arr(n, -1);
  for (long long i = 0; i < n; i++) arr[i] = -1;
  while (m--) {
    cin >> pos >> num;
    if (arr[pos - 1] != -1 && arr[pos - 1] != num) {
      cout << -1 << '\n';
      return 0;
    }
    arr[pos - 1] = num;
  }
  if (arr[0] == 0) {
    cout << -1 << '\n';
    return 0;
  }
  for (long long i : arr) cout << ((i > 0) ? i : 0);
  cout << '\n';
  return 0;
}
