#include <bits/stdc++.h>
using namespace std;
int n, m;
int s[6], c[6];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int(i) = 0; i < (m); (i)++) cin >> s[i] >> c[i];
  bool flag = true;
  int ans[10];
  for (int(i) = 0; i < (10); (i)++) ans[i] = 0;
  for (int(i) = 0; i < (m); (i)++) {
    if (s[i] == n && c[i] == 0)
      flag = false;
    else if (s[i] > n)
      flag = false;
    else if (ans[s[i]] != 0 && ans[s[i]] != (char)c[i])
      flag = false;
    else
      ans[s[i]] = c[i];
  }
  if (ans[n] == 0) flag = false;
  if (flag) {
    for (int i = n; i > 0; i--) {
      if (i == n + 1) break;
      cout << ans[i];
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
