#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
long long GCD(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return GCD(y, x % y);
}
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
const int MOD = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  multimap<int, char> a;
  for (int i = 0; i < m; i++) {
    int x;
    char y;
    cin >> x >> y;
    auto z = a.find(x);
    if (z == a.end()) {
      a.insert(make_pair(x, y));
    } else {
      if (z->second != y) {
        cout << -1;
        return 0;
      }
    }
  }
  string ans = "-1";
  for (int i = 1; i <= 999; i++) {
    string s = to_string(i);
    if (s.length() == n) {
      bool f = true;
      for (auto e : a) {
        if ((s[e.first - 1] != e.second)) {
          f = false;
          break;
        }
      }
      if (f) {
        ans = s;
        break;
      }
    }
  }
  cout << ans;
}
