#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int n, m;
int s, c;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  vector<int> a(n + 1, 0);
  for (int i = 0; i < (int)(m); ++i) {
    cin >> s >> c;
    if (a[s] == 0) {
      a[s] = c;
      continue;
    }
    if (a[s] != c) {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (a[1] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 1; i <= (int)(n); ++i) {
    cout << a[i];
  }
  cout << endl;
}
