#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (a[s] != 0 && a[s] != c) {
      cout << "-1" << endl;
      return 0;
    } else if (s == 0 && c == 0) {
      cout << "-1" << endl;
      return 0;
    } else {
      a[s] = c;
    }
  }
  if (a[0] == 0) {
    a[0] = 1;
  }
  int sum = 0;
  int dig = 1;
  for (int i = 0; i < (int)(n); i++) {
    sum += a[n - i - 1] * dig;
    dig *= 10;
  }
  cout << sum << endl;
  return 0;
}
