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