#include <bits/stdc++.h>
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 mod = 1e9 + 7;
const int inf = 1 << 30;
int ans[5];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (int)(n); i++) ans[i] = -1;
  for (int i = 0; i < (int)(m); i++) {
    int s;
    cin >> s;
    s--;
    int c;
    cin >> c;
    if (s == 0 && c == 0) {
      cout << -1 << endl;
      return 0;
    } else if (ans[s] == -1 || ans[s] == c)
      ans[s] = c;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  string s;
  for (int i = 0; i < (int)(n); i++) {
    if (ans[i] != -1)
      s += to_string(ans[i]);
    else if (i == 0)
      s += '1';
    else
      s += '0';
  }
  cout << s << endl;
}
