#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> um(n, -1);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    --s;
    if (um[s] == -1) {
      um[s] = c;
    } else if (um[s] == c) {
      continue;
    } else {
      cout << -1 << endl;
      return;
    }
  }
  if (um[n - 1] == -1) {
    um[n - 1] = 1;
  }
  for (int i = 0; i < n; i++) {
    if (um[i] == -1) um[i] = 0;
  }
  const int ans = um[0] * 100 + um[1] * 10 + um[2];
  if (ans < pow(10, n - 1)) {
    cout << -1 << endl;
    return;
  }
  cout << ans << endl;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  solve();
  return 0;
}
