#include <bits/stdc++.h>
const long long INF = 1LL << 60;
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main(void) {
  long long N, M, s[10], c[10], i, j, judge = 1, ans;
  cin >> N >> M;
  vector<pair<long long, long long>> p(M);
  for (i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    p[i].first = s[i];
    p[i].second = c[i];
  }
  sort(p.begin(), p.end());
  if (M >= 2) {
    for (i = 0; i < M - 1; i++) {
      if (p[i].first == p[i + 1].first && p[i].second != p[i + 1].second) {
        judge = 0;
      }
    }
  }
  for (i = 0; i < M; i++) {
    if (p[i].first == 1 && p[i].second == 0 && N > 1) {
      judge = 0;
    }
  }
  ans = 0;
  if (judge == 1) {
    for (i = 1; i <= N; i++) {
      for (j = 0; j < M; j++) {
        if (j < M - 1) {
          while (p[j].first == p[j + 1].first) {
            j++;
          }
        }
        if (i == p[j].first) {
          ans += pow(10, N - p[j].first) * p[j].second;
        }
      }
    }
    if (ans < pow(10, N - 1)) ans += pow(10, N - 1);
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
