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