#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
const int N = 100000 + 5;
const int M = 3000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int dx[] = {0, 1, -1, 0, 1, -1, 1, -1};
const int dy[] = {1, 0, 0, -1, 1, -1, -1, 1};
const double PI = acos(-1);
template <class T>
inline T readT() {
  T res = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
  return res * f;
}
int n, m, ans = 0;
int lim[5];
inline bool check(int x) {
  if (!x) return n == 1 && lim[1] == 0;
  int tmp = x, len = 0;
  while (tmp) len++, tmp /= 10;
  for (int i = len; i >= 1; i--, x /= 10) {
    if (x % 10 != lim[i] && lim[i] != -1) return false;
  }
  return len == n;
}
int main() {
  cin >> n >> m;
  memset(lim, -1, sizeof(lim));
  for (int i = 1; i <= m; i++) {
    int s, c;
    cin >> s >> c;
    if (lim[s] == -1)
      lim[s] = c;
    else if (lim[s] != c)
      ans = -1;
  }
  bool flag = false;
  if (ans != 0) {
    flag = true;
    printf("%d\n", ans);
  } else {
    for (int i = 0; i <= 999; i++) {
      if (check(i)) {
        printf("%d\n", i);
        flag = true;
        break;
      }
    }
  }
  if (!flag) puts("-1");
  return 0;
}
