#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  vector<int> cnt = {0, 0, 0};
  vector<int> ans = {1, 0, 0};
  for (int i = 0; i < (int)m; i++) {
    cin >> s[i] >> c[i];
    if (cnt[s[i] - 1] == 0) {
      ans[s[i] - 1] = c[i];
      cnt[s[i] - 1]++;
    } else {
      if (ans[s[i] - 1] != c[i]) {
        cout << -1;
        return 0;
      }
    }
  }
  if (m == 0) {
    for (int i = 0; i < (int)n; i++) {
      if (n == 1)
        cout << -1;
      else
        cout << ans[i];
    }
    return 0;
  }
  if (n > 1 && ans[0] == 0) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < (int)n; i++) {
    cout << ans[i];
  }
  return 0;
}
