#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, k;
  int digit, num;
  bool flag = false;
  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)) flag = true;
    if ((digit - 1 == 0 && num == 0) && N != 1) flag = true;
    gv[digit - 1] = num;
  }
  if (flag) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < (N); i++) ans += gv[i] * pow(10.0, (double)(N - 1 - i));
  cout << ans << endl;
  return 0;
}
