#include <bits/stdc++.h>
using namespace std;
const long long LongINF = 1e13 + 7;
const int INF = 1e9 + 7;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class Y>
T GCD(T a, Y b) {
  if (a < b) {
    int c = a;
    a = b;
    b = c;
  }
  if (a % b == 0) {
    return b;
  }
  return GCD(b, a % b);
}
void clear(queue<pair<int, int>>& q) {
  queue<pair<int, int>> empty;
  swap(q, empty);
}
int main() {
  int N, M;
  cin >> N >> M;
  bool ans = true;
  vector<string> P(10, "-1");
  string S;
  for (int i = (0); i < (N); i++) {
    S.push_back('0');
  }
  for (int i = (0); i < (M); i++) {
    int s;
    string c;
    cin >> s >> c;
    s--;
    if ((s == 0 && N != 1 && c == "0") || (P[s] != c && P[s] != "-1")) {
      ans = false;
    }
    P[s] = c;
    S.erase(S.begin() + s);
    S.insert(S.begin() + s, c[0]);
  }
  if (S[0] == '0') {
    S[0] = '1';
  }
  if (!ans) {
    cout << -1 << endl;
    return 0;
  }
  cout << S << endl;
  return 0;
}
