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