#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  int i, j;
  int digit, num;
  int ans = 0;
  cin >> N >> M;
  vector<int> gv(N);
  for (int i = 0; i < (M); i++) {
    cin >> digit;
    cin >> num;
    if ((gv[digit - 1] != 0 && gv[digit - 1] != num) ||
        (digit - 1 == 0 && num == 0)) {
      cout << "-1" << endl;
      return 0;
    }
    gv[digit - 1] = num;
  }
  for (int i = 0; i < (N); i++) ans += gv[i] * pow(10.0, (double)(N - 1 - i));
  cout << ans << endl;
  return 0;
}
