#include <bits/stdc++.h>
using namespace std;
namespace STARTER {
int MAX(int a, int b) { return a > b ? a : b; }
int MIN(int a, int b) { return a < b ? a : b; }
int ABS(int a) { return a < 0 ? -a : a; }
int GCD(int a, int b) { return !b ? a : GCD(b, a % b); }
int LCM(int a, int b) { return a / GCD(a, b) * b; }
int QSM(int a, int b, int p) {
  int ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % p;
    a = a * a % p;
    b >>= 1;
  }
  return ret;
}
int ROUND(double a) { return a + 0.5; }
}  // namespace STARTER
using STARTER::ABS;
using STARTER::GCD;
using STARTER::LCM;
using STARTER::MAX;
using STARTER::MIN;
using STARTER::QSM;
using STARTER::ROUND;
const int poww[] = {1, 10, 100};
int n, m;
int number[4];
bool used[4];
int main() {
  cin >> n >> m;
  if (!m) {
    if (n == 1) {
      puts("0");
      return 0;
    }
    number[1] = 1;
    for (int i = 1; i <= n; i++) cout << number[i];
    puts("");
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && !c) {
      puts("-1");
      return 0;
    }
    if (used[s] && number[s] != c) {
      puts("-1");
      return 0;
    }
    number[s] = c;
    used[s] = true;
  }
  for (int i = 1; i <= n; i++) cout << number[i];
  puts("");
  return 0;
}
