#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e6 + 5;
vector<int> freq(5);
int main() {
  int n, m;
  cin >> n >> m;
  unordered_map<int, int> st;
  vector<int> aaa(inf);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (st.find(a) != st.end() && st[a] != b) {
      cout << -1;
      exit(0);
    } else {
      st.insert({a, b});
      aaa[a] = b;
    }
  }
  bool allZero = true;
  for (int i = 1; i <= n; i++) {
    if (aaa[i] != 0) {
      allZero = false;
    }
  }
  for (int i = 1; i <= n && !allZero; i++) {
    cout << aaa[i];
  }
  if (allZero) {
    cout << -1;
  }
}
