#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  const int max_n = 3;
  const int max_m = 5;
  int s[max_m + 1];
  int c[max_m + 1];
  int num[max_n + 1];
  cin >> n >> m;
  for (int i = 0; i < n; i++) num[i] = 0;
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < m; i++) s[i] -= 1;
  bool f = 0;
  for (int i = 0; i < m; i++) {
    if (num[s[i]] == 0) {
      num[s[i]] = c[i];
    } else if (num[s[i]] != c[i]) {
      f = 1;
    }
  }
  if (num[0] == 0 && n != 1) f = 1;
  if (f == 1) {
    cout << -1 << endl;
  } else {
    if (n == 1)
      cout << num[0] << endl;
    else if (n == 2)
      cout << num[0] * 10 + num[1] << endl;
    else
      cout << num[0] * 100 + num[1] * 10 + num[2] * 1 << endl;
  }
  return 0;
}
