#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using ve = vector<T>;
template <typename T>
using pq2 = priority_queue<T>;
template <typename T>
using pq1 = priority_queue<T, vector<T>, greater<T>>;
int main() {
  int N, M;
  cin >> N >> M;
  vi ans(N, -1);
  for (int i = 0; i < (M); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (ans[s] == -1)
      ans[s] = c;
    else if (ans[s] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (ans[0] == 0 && N > 1) {
    cout << -1 << endl;
    return 0;
  }
  if (ans[0] == -1) ans[0] = 1;
  for (int i = 0; i < (N); i++) cout << (ans[i] == -1 ? 0 : ans[i]);
  cout << endl;
  return 0;
}
