#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 && c[i] == 0 && N != 1) {
      cout << -1;
      return 0;
    }
  }
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1;
        return 0;
      }
    }
  }
  vector<int> z(N);
  for (int i = 0; i < N; i++) {
    z[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    z[s[i]] = c[i];
  }
  double ans = 0;
  for (int i = 1; i < N + 1; i++) {
    ans += (double)z[i] * pow(10.0, (double)(N - i));
  }
  int t = (int)ans;
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (t != 0 || (count == 0 && t == 0)) {
      t /= 10;
      count++;
    }
  }
  if (count != N) {
    cout << -1;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
