#include <bits/stdc++.h>
using namespace std;
int n, m;
int ans[3];
int ok = true;
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  cin >> n >> m;
  ans[0] = -1;
  ans[1] = -1;
  ans[2] = -1;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (ans[s - 1] < 0 || ans[s - 1] == c)
      ans[s - 1] = c;
    else
      ok = false;
  }
  if (ans[0] == 0 && n != 1) ok = false;
  if (ans[0] == -1) ans[0] = 1;
  if (ans[1] == -1) ans[1] = 0;
  if (ans[2] == -1) ans[2] = 0;
  if (ok) {
    for (int i = 0; i < n; i++) cout << ans[i];
  } else
    cout << -1;
  return 0;
}
