#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int inf = 1e9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  int n, m;
  cin >> n >> m;
  string s = "";
  for (int i = 0; i < n; i++) {
    s += '0';
  }
  pair<int, char> v[10];
  for (int i = 0; i < m; i++) {
    cin >> v[i].first >> v[i].second;
    if (v[i].first == 1 && v[i].second == '0' && n > 1) {
      cout << -1 << endl;
      return 0;
    }
    s[v[i].first - 1] = v[i].second;
  }
  for (int i = 0; i < m; i++) {
    if (s[v[i].first - 1] != v[i].second) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << s << endl;
  return 0;
}
