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