#include <bits/stdc++.h>
using namespace std;
constexpr int kMod = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> v(N, 0);
  vector<bool> used(N);
  for (int i = 0; i < M; ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (used[s] && v[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    v[s] = c;
    used[s] = true;
  }
  if (used[0] && v[N - 1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (used[0])
    cout << v[0];
  else
    cout << 1;
  for (int i = 1; i < N; ++i) cout << v[i];
  cout << endl;
}
