#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
using Graph = vector<vector<int>>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M);
  vector<int> C(M);
  for (long long i = 0; i < (long long)(M); ++i) {
    cin >> S[i] >> C[i];
  }
  for (long long i = 0; i < (long long)(M); ++i) {
    if (S[i] == 1) {
      if (C[i] == 0) {
        if (N != 1) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
  }
  for (int i = 0; i < M - 1; i++) {
    for (int j = i + 1; j < M; j++) {
      if (S[i] == S[j]) {
        if (C[i] != C[j]) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
  }
  vector<bool> check(N, false);
  int ans = 0;
  for (int i = 0; i < M; i++) {
    if (check[S[i] - 1] == false) {
      ans += pow(10, (N - S[i])) * C[i];
      check[S[i] - 1] = true;
    }
  }
  if (check[0] == false) {
    ans += pow(10, N - 1);
  }
  cout << ans << endl;
  return 0;
}
