#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  bool flag = false;
  vector<int> v(N, -1);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (v[s] < 0)
      v[s] = c;
    else if (v[s] != c)
      flag = true;
  }
  if (flag) {
    cout << "-1\n";
    return 0;
  }
  if (N == 1) {
    cout << v[0] << "\n";
    return 0;
  }
  if (v[0] == 0) {
    cout << "-1\n";
    return 0;
  }
  cout << (v[0] < 0 ? 1 : v[0]);
  for (int i = 1; i < N; i++) cout << (v[i] < 0 ? 0 : v[i]);
}
