#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> X;
  bool dame = 0;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (X.count(s) && c != X[s])
      dame = 1;
    else
      X[s] = c;
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (!X.count(i)) X[i] = 0;
    ans += X[i] * pow(10, N - i);
  }
  if (X[1] == 0) dame = 1;
  if (dame)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
