#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  map<int, int> m;
  for (int i = 0; i < N; i++) m[i] = -1;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (m[s] != -1) {
      cout << -1 << endl;
      return 0;
    }
    m[s] = c;
  }
  ll ans = 0;
  for (int i = 0; i < M; i++) {
    if (m[i] != -1) ans += pow(10, i) * m[M - 1 - i];
  }
  if (ans < 0)
    cout << -1 << endl;
  else if (ans == 0 && N != 1)
    cout << -1 << endl;
  else if (ans < pow(10, N - 1)) {
    ans += pow(10, N - 1);
    cout << ans << endl;
  } else
    cout << ans << endl;
  return 0;
}
