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