#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long to, cost;
};
const long long INF = 100000000000000000;
const long long INF2 = 9223372036854775807;
const long long MOD = 1000000007;
long long ceil2(long long a, long long b) {
  if (a % b == 0) {
    return a / b;
  } else {
    return a / b + 1;
  }
}
long long pow2(long long a, long long b) {
  long long r = 1;
  for (long long i = 1; i <= b; i++) {
    r *= a;
  }
  return r;
}
long long Log2(long long a) {
  long long t = 0;
  while (1) {
    if (a == 0 || a == 1) {
      break;
    }
    a /= 2;
    t++;
  }
  return t;
}
long long N, M;
long long A[10], B[10];
long long C[3];
signed main() {
  cin >> N >> M;
  for (long long i = 0; i < (long long)(M); i++) {
    cin >> A[i] >> B[i];
    A[i]--;
  }
  for (long long i = 0; i < (long long)(3); i++) {
    C[i] = -1;
  }
  long long R;
  if (N == 3) {
    R = 999;
  } else if (N == 2) {
    R = 99;
  } else {
    R = 9;
  }
  for (long long i = 0; i <= R; i++) {
    long long num = i / 100;
    if (i < 100) {
      num = -1;
    }
    long long num2 = (i - num * 100) / 10;
    if (i < 10) {
      num2 = -1;
    }
    long long num3 = i % 100 % 10;
    bool flag = true;
    for (long long j = 0; j < (long long)(M); j++) {
      if (A[j] == 0) {
        if (B[j] != num) {
          flag = false;
        }
      }
      if (A[j] == 1) {
        if (B[j] != num2) {
          flag = false;
        }
      }
      if (A[j] == 2) {
        if (B[j] != num3) {
          flag = false;
        }
      }
    }
    if (flag == true) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
