#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
int pow(int x, int y) {
  if (y == 0) return 1;
  int X = 1;
  for (int i = 0; i < y; i++) {
    X *= x;
  }
  return X;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> v(N);
  bool memo[3];
  bool can = true;
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    if (!memo[x - 1]) {
      memo[x - 1] = true;
      v.at(x - 1) = y;
    } else if (memo[x - 1] && y != v.at(x - 1)) {
      can = false;
      break;
    }
  }
  if (!memo[0]) v.at(0) = 1;
  if (v.size() != 1 && v.at(0) == 0) can = false;
  if (!can) cout << -1 << endl;
  if (can) {
    int ans;
    for (int i = 0; i < N; i++) {
      ans += pow(10, N - i - 1) * v.at(i);
    }
    cout << ans << endl;
  }
}
