#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    long long n;
    cin >> n;
    long long m;
    cin >> m;
    string s = "";
    for (long long i = 0; i < n; i++) s += "a";
    long long flag = 0;
    for (long long i = 0; i < m; i++) {
      long long a, b;
      cin >> a >> b;
      a--;
      char c = '0' + b;
      if (s[a] != 'a' and s[a] != c) {
        flag = 1;
        break;
      } else
        s[a] = c;
    }
    if (flag)
      cout << "-1\n";
    else {
      for (long long i = 0; i < n; i++)
        if (s[i] == 'a') s[i] = '0';
      cout << s;
    }
  }
}
