#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int i, m, n, x;
  bool visited[5] = {0};
  string s, ans = "000";
  cin >> n >> m;
  while (m--) {
    cin >> x >> s;
    if (!visited[--x]) {
      ans[x] = s[0];
      visited[x] = true;
    } else
      ans[x] = min(ans[x], s[0]);
  }
  if (!visited[0] || ans[0] == '0') {
    cout << "-1";
    return 0;
  }
  for (i = 0; i < n; i++) cout << ans[i];
  return 0;
}
