#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int x[N], y[N], n, m, k, num = 1;
int main() {
  cin >> n >> m;
  if (n == 1 && m == 0) {
    puts("0");
    return 0;
  }
  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i];
  }
  for (int i = 1; i < n; i++) num *= 10;
  for (int i = num; i < num * 10; i++) {
    bool flag = true;
    for (int j = 0; j < m; j++) {
      int rem = i;
      for (int k = n; k > x[j]; k--) {
        rem /= 10;
      }
      rem %= 10;
      if (rem != y[j]) flag = false;
    }
    if (flag) {
      cout << i << "\n";
      return 0;
    }
  }
  puts("-1");
}
