#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 100000000;
int ten(int n) {
  if (n == 0) {
    return 1;
  }
  return ten(n - 1) * 10;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < m; i++) {
    if (n != 1 && s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      if (s[i] == s[j]) {
        if (c[i] != c[j]) {
          cout << -1 << endl;
          return 0;
        } else {
          c[j] = 0;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    ans += c[i] * ten(n - s[i]);
  }
  if (ans >= ten(n)) {
    cout << ans << endl;
  } else {
    if (ans != 0) {
      ans = ten(n) + ans;
      cout << ans << endl;
    } else {
      cout << ans << endl;
    }
  }
}
