#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  int ans[n];
  int s, c;
  for (int i = 0; i < n; i++) ans[i] = 0;
  for (int i = 0; i < (int)m; i++) {
    cin >> s >> c;
    if (ans[s - 1] == 0 || ans[s - 1] == c) {
      ans[s - 1] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  int cnt = 0;
  for (int i = 0; i < (int)n; i++) {
    if (ans[i] == 0) cnt++;
  }
  if (cnt == n) {
    cout << -1 << endl;
    return 0;
  }
  bool flag = true;
  if (ans[0] == 0) flag = false;
  for (int i = 0; i < (int)n; i++) {
    if (flag) cout << ans[i];
    if (ans[i + 1] != 0) flag = true;
  }
  cout << endl;
  return 0;
}
