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