#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 20, BL = 400;
const double EPS = 3e-16;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<char> a(n, '#');
  vector<long long> t(n, 0);
  while (m--) {
    long long s;
    cin >> s;
    char c;
    cin >> c;
    s--;
    if (a[s] != '#' && c != a[s]) {
      return cout << "-1", 0;
    }
    a[s] = c;
  }
  if (a[0] == '#' || (n > 1 && a[0] == '0')) return cout << "-1", 0;
  for (long long i = 0; i < n; i++) {
    if (a[i] == '#')
      cout << 0;
    else
      cout << a[i];
  }
  return 0;
}
