#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
const long long mod = 1000000007;
long long digits(long long m) {
  long long count = 0;
  while (m > 0) {
    m /= 10;
    count++;
  }
  return count;
}
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> a;
  for (long long int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (a[s] != 0 && a[s] != c) {
      std::cout << -1 << std::endl;
      return 0;
    }
    a[s] = c;
  }
  for (long long int i = 0; i < 1000; i++) {
    bool flag = true;
    if (digits(i) != n) continue;
    string num_to_s = to_string(i);
    for (auto it : a) {
      if (num_to_s[it.first - 1] - '0' != it.second) {
        flag = false;
        break;
      }
    }
    if (flag) {
      std::cout << i << std::endl;
      return 0;
    }
  }
  std::cout << -1 << std::endl;
}
