#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using Pc = pair<double, int>;
using T = tuple<int, int, int>;
using edge = struct {
  int to;
  long long dist;
};
const double PI = 3.141592653589793;
long long fact[2000005], inv[2000005];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
vector<vector<int>> bingo(3, vector<int>(3));
vector<vector<int>> tree(100005);
int color[100005];
map<P, int> colorMap;
int m = 0;
struct BridgeInfo {
  int town1;
  int town2;
  int year;
  BridgeInfo(int t1, int t2, int y) {
    town1 = t1;
    town2 = t2;
    year = y;
  }
};
struct People {
  int index;
  int town;
  int year;
  People(int i, int t, int y) {
    index = i;
    town = t;
    year = y;
  }
};
bool compare_by_second(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}
struct UnionFind {
  vector<int> uf;
  UnionFind(int size) : uf(size, -1){};
  int root(int target) {
    if (uf[target] < 0)
      return target;
    else
      return uf[target] = root(uf[target]);
  }
  void merge(int a, int b) {
    a = root(a);
    b = root(b);
    if (a == b) return;
    if (uf[b] < uf[a]) swap(a, b);
    uf[a] += uf[b];
    uf[b] = a;
  }
};
long long CalcPow(long long num, long long power) {
  if (power == 0) return 1;
  if (power % 2 == 0) {
    long long half = CalcPow(num, power / 2);
    return (half * half) % 1000000007;
  } else
    return (num * CalcPow(num, power - 1)) % 1000000007;
}
long long combination(long long all, long long select) {
  if (all < select) return 0;
  if (all < 0 || select < 0) return 0;
  return fact[all] * (inv[select] * inv[all - select] % 1000000007) %
         1000000007;
}
void initCombination(int max) {
  fact[0] = fact[1] = 1;
  for (int i = 2; i <= max; ++i) {
    fact[i] = fact[i - 1] * i % 1000000007;
  }
  inv[max] = CalcPow(fact[max], 1000000007 - 2);
  for (int i = max - 1; 0 <= i; --i) {
    inv[i] = (inv[i + 1] * (i + 1)) % 1000000007;
  }
}
void dfs(int from) {
  int c = 1;
  for (auto t : tree[from]) {
    c = c != color[from] ? c : c + 1;
    color[t] = c;
    colorMap[make_pair(from, t)] = c;
    m = max(c, m);
    dfs(t);
    c++;
  }
}
int main() {
  int N, M;
  cin >> N >> M;
  map<int, string> m;
  for (int i = 0; i < N; ++i) {
    m[i] = "-1";
  }
  string ans;
  for (int i = 0; i < M; ++i) {
    int s;
    string c;
    cin >> s;
    cin >> c;
    s--;
    if (m[s] != "-1" && m[s] != c) {
      cout << "-1" << endl;
      return -1;
    } else {
      m[s] = c;
    }
  }
  for (int i = 0; i < N; ++i) {
    if (N != 1 && i == 0 && m[i] == "0") {
      cout << "-1" << endl;
      return -1;
    }
    if (m[i] == "-1" && i == 0 && N != 1)
      ans += "1";
    else if (m[i] == "-1")
      ans += "0";
    else
      ans += m[i];
  }
  cout << ans << endl;
}
