#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
using namespace std;
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T lcm(T a, T b) {
  return a * b / gcd(a, b);
}
template <typename T>
T binarysearch(vector<T> A, T key) {
  long long left = 0;
  long long right = 4;
  long long mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (key == A[mid]) return 1;
    if (key > A[mid])
      left = mid + 1;
    else if (key < A[mid])
      right = mid;
  }
  return 0;
}
template <typename T>
T finder(vector<T> vec, T number) {
  auto itr = find(vec.begin(), vec.end(), number);
  size_t index = distance(vec.begin(), itr);
  if (index != vec.size()) {
    return 1;
  } else {
    return 0;
  }
}
long long frac(long long n) {
  if (n == 0) {
    return 1;
  }
  return (n * frac(n - 1)) % MOD;
}
template <typename T>
T keta(T a) {
  long long kazu = 1;
  while (1) {
    if (a / 10 != 0) {
      a /= 10;
      kazu++;
    } else
      break;
  }
  return kazu;
}
template <typename T>
T nCr(long long n, T r) {
  long long ans = 1;
  for (int i = n; i > n - r; --i) {
    ans = ans * i;
  }
  for (int i = 1; i < r + 1; ++i) {
    ans = ans / i;
  }
  return ans;
}
int main() {
  long long N, M;
  cin >> N >> M;
  bool OK = true;
  vector<long long> s(M), c(M);
  long long ans = 0;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 && c[i] == 0) OK = false;
  }
  for (int i = 0; i < M - 1; i++) {
    for (int l = i + 1; l < M; l++) {
      if (s[i] == s[l]) {
        if (c[i] == c[l])
          c[l] = 0;
        else
          OK = false;
      }
    }
  }
  for (int i = 0; i < M; i++) {
    ans += pow(10, N - s[i]) * c[i];
  }
  if (keta(ans) != N) {
    ans += pow(10, N - 1);
  }
  if (!OK) ans = -1;
  cout << ans << endl;
}
