#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  ll ans[N];
  for (int i = 0; i < N; i++) ans[i] = -1;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (ans[s] != -1 && ans[s] != c) {
      cout << -1;
      return 0;
    }
    ans[s] = c;
  }
  if (ans[0] == 0 && N != 1) {
    cout << -1;
    return 0;
  }
  ll foroutput = 0, tmp = 1;
  for (int i = N - 1; i >= 0; i--) {
    if (ans[i] != -1)
      foroutput += tmp * ans[i];
    else if (i == 0)
      foroutput += tmp;
    tmp *= 10;
  }
  cout << foroutput;
  return 0;
}
