#include <bits/stdc++.h>
using namespace std;
int syc(long i, long Min, long Max) {
  if (Min <= i && i <= Max) {
    return 1;
  } else {
    exit(1);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m], ans[n];
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  for (int i = 0; i < n; i++) {
    ans[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    if (ans[s[i] - 1] == 0) {
      ans[s[i] - 1] = c[i];
    } else if (ans[s[i] - 1] != 0 && ans[s[i] - 1] != c[i]) {
      cout << "-1" << endl;
      return 0;
    } else {
    }
  }
  if (ans[0] == 0) {
    ans[0] = 1;
  }
  int ans_is = 0;
  for (int i = 0; i < n; i++) {
    ans_is += ans[i] * pow(10, n - 1 - i);
  }
  if (0 < ans_is && pow(10, n - 1) < ans_is && ans_is < pow(10, n)) {
    cout << ans_is << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
