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