#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long linf = 1e18;
template <class T>
void chmin(T& x, T y) {
  if (x > y) x = y;
}
template <class T>
void chmax(T& x, T y) {
  if (x < y) x = y;
}
int N;
int M;
int ans = 0;
int digi[4] = {-1, -1, -1, -1};
bool flag = true;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (digi[s] == c)
      continue;
    else if (digi[s] != -1)
      flag = false;
    if (s == 1 && c == 0) {
      if (N == 1)
        digi[s] = c;
      else
        flag = false;
    }
    digi[s] = c;
    for (; s < N; s++) {
      c *= 10;
    }
    ans += c;
  }
  if (digi[1] == -1) {
    int add = 1;
    for (int i = 1; i < N; i++) {
      add *= 10;
    }
    ans += add;
  }
  cout << (flag ? ans : -1) << endl;
  return 0;
}
