#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const vector<long long int> dx = {1, -1, 0, 0};
const vector<long long int> dy = {0, 0, 1, -1};
template <typename T = long long int>
vector<T> ga(long long int n, bool oneIndexed = false) {
  vector<T> a = vector<T>(n + oneIndexed);
  for (long long int i = 0; i < n; i++) {
    T p;
    cin >> p;
    a[i + oneIndexed] = p;
  }
  return move(a);
}
template <typename T, typename A>
void pa(vector<T, A> const &a, long long int begin = 0,
        long long int end = -1) {
  if (end == -1) end = (long long int)a.size() - 1;
  for (long long int i = begin; i <= end; i++) {
    cout << a[i] << " ";
  }
  cout << "\n";
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  vector<long long int> digs(n, -1);
  while (m--) {
    long long int s, c;
    cin >> s >> c;
    if (digs[s - 1] == -1)
      digs[s - 1] = c;
    else if (digs[s - 1] != c) {
      cout << "-1\n";
      return;
    };
  }
  if (digs[0] == -1) {
    cout << "-1\n";
    return;
  };
  for (auto x : digs)
    if (x == -1)
      cout << 1;
    else
      cout << x;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  solve();
  return 0;
}
