#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string ans;
  vector<pair<int, char>> p(m);
  for (int i = 0; i < m; i++) cin >> p[i].first >> p[i].second;
  for (int i = 0; i < n; i++) {
    ans += "n";
  }
  for (int i = 0; i < m; i++) {
    if (p[i].second != ans[p[i].first - 1]) {
      if (ans[p[i].first - 1] == 'n')
        ans[p[i].first - 1] = p[i].second;
      else {
        ans = "-1";
        break;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (ans == "-1") break;
    if (i == 0 && (ans[i] == 'n' || ans[i] == '0')) {
      if (ans.size() == 1)
        ans = '0';
      else {
        ans = "-1";
        break;
      }
    }
    if (ans[i] == 'n') ans[i] = '0';
  }
  cout << ans << endl;
}
