#include <bits/stdc++.h>
using namespace std;
const long long INF = 100100100100;
long long combination(long long n, long long r) {
  if (n < r) return 0;
  if (r == 0 || r == n)
    return 1;
  else if (r == 1)
    return n;
  return (combination(n - 1, r - 1) + combination(n - 1, r));
}
bool checkKaibun(string str) {
  string checkStr = str;
  reverse(checkStr.begin(), checkStr.end());
  if (str == checkStr)
    return true;
  else
    return false;
}
int keta(long long num) {
  int digits = 0;
  while (num > 0) {
    num /= 10;
    digits++;
  }
  return digits;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (long long i = 0; i < M; i++) cin >> s[i] >> c[i];
  int maxNum = 0;
  int startNum = 0;
  if (N == 2) {
    startNum = 10;
    maxNum = 100;
  } else if (N == 3) {
    startNum = 100;
    maxNum = 1000;
  }
  for (int ans = startNum; ans < maxNum; ans++) {
    bool flag = true;
    for (long long i = 0; i < M; i++) {
      string str = to_string(ans);
      if (str[s[i] - 1] != (c[i] + 48)) flag = false;
    }
    if (flag == true) {
      cout << ans << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
