#include <bits/stdc++.h>
using ll = long long;
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INFLL = 1LL << 60;
const int INF = 1 << 28;
void solve(int a) { cout << (a ? "Yes" : "No") << endl; }
int main() {
  int n, m;
  int ans = 0;
  cin >> n >> m;
  int a, b;
  vector<int> c(n + 1, 10);
  int d = 1;
  for (int i = 0, i_len = (int)(m); i < i_len; i++) {
    cin >> a >> b;
    if (c[a] == b or c[a] == 10) {
      c[a] = b;
    } else {
      ans = -1;
    }
  }
  if (n != 1 and c[1] == 0) {
    ans = -1;
  }
  if (ans != -1) {
    for (int i = n; i >= 1; i--) {
      if (c[i] != 10) {
        ans += c[i] * d;
      }
      if (i == 1 and c[1] == 0) {
        if (n != 1) {
          ans += 1 * d;
        }
      }
      d *= 10;
    }
  }
  cout << ans << endl;
}
