#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  for (int i = 0; i < m; i++) {
  }
  for (int i = 0; i < m; i++) {
  }
  int f[m];
  int ans_ary[m];
  for (int i = 0; i < m; i++) {
    f[i] = m - i;
    ans_ary[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    if (ans_ary[s[i] - 1] == 0 || ans_ary[s[i] - 1] == c[i]) {
      ans_ary[s[i] - 1] = c[i];
    } else {
      return 0;
    }
  }
  bool flg = false;
  for (int i = 0; i < m; i++) {
    if (ans_ary[i] != 0) {
      flg = true;
      cout << ans_ary[i];
    } else if (flg == true) {
      cout << ans_ary[i];
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << endl;
}
