#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, '#');
  for (long long i = 0; i < m; i++) {
    long long s;
    char c;
    cin >> s >> c;
    s--;
    if (n == 1 && m == 1) {
      return cout << c, 0;
    }
    if (a[s] != '#' && a[s] != c) return cout << "-1", 0;
    a[s] = c;
  }
  if (m == 1 && n > 1 && a[0] == '0') {
    cout << "-1";
    return 0;
  }
  bool no = false;
  for (long long i = 0; i < n; i++) {
    if (a[i] == '#' && !no) return cout << "-1", 0;
    if (a[i] == '#')
      a[i] = '0';
    else
      no = true;
    cout << a[i];
  }
  return 0;
}
