#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1000000000;
signed main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> numbers(N);
  for (ll i = 0; i < (M); ++i) {
    ll s, c;
    cin >> s >> c;
    s--;
    if (numbers[s] == 0 || numbers[s] == c) {
      if (s == 0 && c == 0) {
        cout << (-1) << endl;
        return 0;
      }
      numbers[s] = c;
    } else {
      cout << (-1) << endl;
      return 0;
    }
  }
  if (N == 1 && numbers[0] == 0) {
    cout << (0) << endl;
    return 0;
  }
  if (numbers[0] == 0) {
    numbers[0] = 1;
  }
  for (ll i = 0; i < (N); ++i) {
    cout << numbers[i];
  }
  cout << endl;
  return 0;
}
