#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  vector<int> s, c;
  bool is_ok = true;
  cin >> N >> M;
  vector<int> ans(N, 0);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    s.push_back(a);
    c.push_back(b);
  }
  for (int i = 0; i < M; i++) {
    if (ans[s[i] - 1] != 0) {
      if (ans[s[i] - 1] != c[i]) {
        is_ok = false;
        break;
      }
    } else {
      ans[s[i] - 1] = c[i];
    }
  }
  if (is_ok) {
    for (int i = 0; i < M; i++) {
      cout << ans[i];
    }
    cout << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
