#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
  int n, m;
  cin >> n >> m;
  string ans;
  for (int i = 0; i < (n); ++i) {
    if (i == 0) {
      ans.insert(0, "1");
    } else {
      ans.insert(i, "0");
    }
  }
  vector<pair<int, string>> a;
  for (int i = 0; i < (m); ++i) {
    int s;
    string t;
    cin >> s >> t;
    s--;
    ans.replace(s, 1, t);
    a.push_back(make_pair(s, t));
  }
  sort(a.begin(), a.end());
  if (m > 1) {
    for (int i = 0; i < (a.size()); ++i) {
      if (a[i].first == a[i + 1].first && a[i].second != a[i + 1].second) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (ans[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
