#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  string s = "";
  vector<bool> vec(n);
  for (long long i = 0; i < (n); i++) {
    s += '0';
    vec[i] = true;
  }
  if (m == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (long long i = 0; i < (m); i++) {
    int a;
    char b;
    cin >> a >> b;
    a--;
    if (a == 0 && b == '0') {
      cout << -1 << endl;
      return 0;
    }
    if (vec[a]) {
      s[a] = b;
      vec[a] = false;
    } else if (!vec[a]) {
      if (s[a] == b)
        continue;
      else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (n > 1 && s[0] == '0') s[0] = '1';
  cout << s << endl;
}
