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