#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, m;
  cin >> n >> m;
  long long s, c;
  if (n == 1 && m == 0) {
    cout << "0";
    return 0;
  }
  vector<long long> v(n, 0);
  vector<long long> arr(n, 0);
  for (long long i = 0; i < m; i++) {
    cin >> s >> c;
    s--;
    if (v[s] != 0 && arr[s] != c) {
      cout << "-1";
      return 0;
    }
    v[s] = 1;
    arr[s] = c;
  }
  string res = "";
  if (v[0] == 0) {
    arr[0] = 1;
  }
  for (long long i = 0; i < n; i++) {
    res += arr[i] + '0';
  }
  if (res.size() == n && res[0] != '0') {
    cout << res;
    return 0;
  }
  cout << "-1";
  return 0;
}
