#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s, c;
  for (int i = (0); i < (int)(m); i += 1) {
    int a, b;
    cin >> a >> b;
    s.push_back(a);
    c.push_back(b);
  }
  int ten = 10;
  for (int i = (1); i < (int)(n); i += 1) {
    ten *= 10;
  }
  int ans = -1;
  bool flag = false;
  for (int i = (0); i < (int)(ten); i += 1) {
    for (int j = (0); j < (int)(m); j += 1) {
      int x;
      switch (s[j] + 3 - n) {
        case 3:
          x = i % 10;
          break;
        case 2:
          x = (i / 10) % 10;
          break;
        case 1:
          x = i / 100;
      }
      if (x != c[j]) {
        break;
      } else {
        if (j == m - 1) {
          flag = true;
          ans = i;
        }
      }
    }
    if (flag) {
      break;
    }
  }
  if (ans == 0 && n != 1) {
    ans = -1;
  }
  if (n != 1 && ten / 10 > ans) {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}
