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