#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  std::cin >> n >> m;
  char str[n];
  str[0] = '1';
  for (int i = 1; i < n; i++) {
    str[i] = '0';
  }
  int s[m];
  char c[m];
  for (int i = 0; i < m; i++) {
    std::cin >> s[i] >> c[i];
    str[s[i] - 1] = c[i];
  }
  for (int i = 0; i < m; i++) {
    std::cin >> s[i] >> c[i];
    str[s[i] - 1] = c[i];
  }
  int ans = -1;
  ans = atoi(str);
  for (int i = 0; i < m; i++) {
    if (str[s[i] - 1] != c[i]) ans = -1;
  }
  std::cout << ans << std::endl;
  return 0;
}
