#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int num[3] = {-1, -1, -1};
  int moves[5][2];
  int n, m, ans = 0;
  bool flag = true;
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> moves[i][0] >> moves[i][1];
  int mult;
  if (n == 3) mult = 100;
  if (n == 2) mult = 10;
  if (n == 3) mult = 1;
  for (int i = 0; i < m; i++) {
    int u = moves[i][0] - 1;
    int v = moves[i][1];
    if (num[u] == -1)
      num[u] = v;
    else if (num[u] != -1 && num[u] != v)
      flag = false;
  }
  for (int i = 0; i < n; i++) {
    if (num[i] == -1) num[i] = 0;
  }
  ans += 100 * num[0] + 10 * num[1] + num[2];
  if (!flag || ans == 0)
    cout << -1 << "\n";
  else
    cout << ans << "\n";
  return 0;
}
