#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
long long A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
long long ans = 0;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}
signed main() {
  cin >> N >> M;
  vector<int> x(N + 1, -1);
  bool flag = 0;
  for (int i = 0; i < (int)(M); i++) {
    int s, c;
    cin >> s >> c;
    if (x[s] == -1) {
      x[s] = c;
    } else {
      if (x[s] == c) {
        continue;
      } else {
        flag = 1;
        break;
      }
    }
  }
  if (x[1] == 0 && N != 1) {
    flag = 1;
  }
  if (x[1] == -1) {
    flag = 1;
  };
  if (flag) {
    cout << -1 << "\n";
  } else {
    for (int i = 0; i < (int)(N + 1); i++) {
      if (x[i] != -1) {
        ans += x[i] * pow(10, N - i);
      }
    }
    cout << ans << "\n";
  }
}
