#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  string ans = "";
  char s[10], c[10];
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < N; i++) {
    ans += '0';
  }
  for (int i = 0; i < M; i++) {
    if (N > 1 && s[i] == '1' && c[i] == '0') {
      cout << "-1" << endl;
      return 0;
    }
    if (ans[s[i] - 49] == '0') {
      ans[s[i] - 49] = c[i];
    } else if (ans[s[i] - 49] != c[i]) {
      ans = "-1";
    }
  }
  if (ans[N - 1] == '0' && N > 1) ans = "-1";
  cout << ans << endl;
  return 0;
}
