#include <bits/stdc++.h>
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char nums[n];
  for (int i = 0; i < (n); ++i) {
    nums[i] = 'X';
  }
  int result = 0;
  for (int i = 0; i < (m); ++i) {
    int s;
    char c;
    cin >> s >> c;
    if (nums[s - 1] == 'X' || nums[s - 1] == c)
      nums[s - 1] = c;
    else {
      result = -1;
      break;
    }
  }
  if (result != 0) {
    cout << result << endl;
    return 0;
  }
  for (int i = 0; i < (n); ++i) {
    if (nums[i] == 'X') nums[i] = '0';
  }
  if (n == 3 && nums[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  if (n == 3 && nums[0] == '0' && nums[1] == '0') {
    cout << -1 << endl;
    return 0;
  }
  if (n == 2 && nums[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (n); ++i) {
    cout << nums[i];
  }
  cout << endl;
  return 0;
}
