#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> used(n, 0);
  vector<int> S(n, 0);
  int ans = 0;
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (s + c == 0 & n > 1) ans = -1;
    if (used[s] == 0) {
      S[s] = c;
    } else {
      if (S[s] != c) ans = -1;
    }
    used[s] = 1;
  }
  if (S[0] == 0 & n > 1) S[0] = 1;
  if (ans == 0) {
    ans += S[0] * 100 + S[1] * 10 + S[2];
  }
  cout << ans;
}
