#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long func2(long long n) {
  long long res = 0;
  while (n % 2 == 0) {
    n /= 2;
    res++;
  }
  return res;
}
long long zyou(long long a, long long b) {
  long long res = 1;
  for (int i = 1; i <= b; i++) {
    res *= a;
  }
  return res;
}
struct Edge {
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<int>>;
long long calc(long long a, long long b, long long p) {
  if (b == 0)
    return 1;
  else if (b % 2 == 0) {
    long long d = calc(a, b / 2, p);
    return (d * d) % p;
  } else if (b % 2 == 1) {
    return (a * calc(a, b - 1, p)) % p;
  }
}
bool is_prime(int n) {
  if (n == 1) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
bool palin(string S) {
  int n = S.size();
  bool flag = true;
  if (n % 2 == 0) {
    for (int i = 0; i <= n / 2 - 1; i++) {
      if (S[i] != S[n - i - 1]) {
        flag = false;
        break;
      }
    }
  } else if (n % 2 == 1) {
    for (int i = 0; i <= n / 2 - 1; i++) {
      if (S[i] != S[n - i - 1]) {
        flag = false;
        break;
      }
    }
  }
  return flag;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < (int)(M); i++) {
    cin >> s[i];
    cin >> c[i];
  }
  string ans = "-1";
  for (int i = 0; i <= 999; i++) {
    string S = to_string(i);
    bool flag = true;
    for (int j = 0; j < M; j++) {
      if (S[s[j] - 1] != (char)(c[j] + 48)) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans = S;
      break;
    }
  }
  if (N >= 2 && ans[0] == '0')
    cout << -1 << endl;
  else
    cout << ans << endl;
}
