#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  os << "{";
  for (int i = 0; i < vec.size(); ++i) os << (i ? ", " : "") << vec[i];
  os << "}";
  return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& rhs) {
  os << "(" << rhs.first << ", " << rhs.second << ")";
  return os;
}
int main() {
  int N, M;
  cin >> N >> M;
  int n[N];
  for (int i = 0; i < (N); ++i) n[i] = -1;
  for (int i = 0; i < (M); ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (n[s] == -1) {
      n[s] = c;
    } else if (n[s] != c) {
      cout << "-1\n";
      return 0;
    }
  }
  if (n[0] == 0 && N > 1) {
    cout << "-1\n";
    return 0;
  }
  if (n[0] == -1) n[0] = 1;
  for (int i = 0; i < (N); ++i) {
    if (n[i] == -1) n[i] = 0;
    cout << n[i];
  }
  cout << endl;
  return 0;
}
